Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 2
Message 1 of 2

Discrepancy in schema between GraphQL Explorer and api.github.com/graphql

Solved! Go to Solution.

Repro:

1. Go to the GitHub GraphQL API Explorer. Issue the following query:

Query:

query Repositories($ids: [ID!]!) {
  nodes(ids:$ids) {
    ... on Repository {
      id
      nameWithOwner
    }
  }
}

Variables:

{
  "ids": [
    "asdf1",
    "MDEwOlJlcG9zaXRvcnkxMTQwNzkxOQ=="
  ]
}

Verify you get a response like the following:

{
  "data": {
    "nodes": [
      null,
      [
        [
          "id",
          "MDEwOlJlcG9zaXRvcnkxMTQwNzkxOQ=="
        ],
        [
          "nameWithOwner",
          "beyang/elastigo"
        ]
      ]
    ]
  },
  "errors": [
    {
      "type": "NOT_FOUND",
      "path": [
        "nodes",
        0
      ],
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "message": "Could not resolve to a node with the global id of 'asdf1'"
    }
  ]
}

If you open Chrome dev tools and "copy as cURL" the request, you'll find it returns the same on the command line.

 

2. Now issue the same request against https://api.github.com/graphql with cURL:

curl -H "Authorization: bearer $TOKEN" -X POST --data-binary '{"query":"query Repositories($ids: [ID!]!) {\n nodes(ids:$ids) {\n ... on Repository {\n id\n nameWithOwner\n }\n }\n}","variables":{"ids":["asdf1","MDEwOlJlcG9zaXRvcnkxMTQwNzkxOQ=="]},"operationName":"Repositories"}' https://api.github.com/graphql

(Replace "$TOKEN" with your personal access token.)

Verify you get a response like the following:

{
 "data": {
  "nodes": [
   null,
   {
    "id": "MDEwOlJlcG9zaXRvcnkxMTQwNzkxOQ==",
    "nameWithOwner": "beyang\/elastigo"
   }
  ]
 },
 "errors": [
  {
   "type": "NOT_FOUND",
   "path": [
    "nodes",
    0
   ],
   "locations": [
    {
     "line": 2,
     "column": 3
    }
   ],
   "message": "Could not resolve to a node with the global id of 'asdf1'"
  }
 ]
}

3. Note that the schema of the "data" field in the response differs between the GraphQL Explorer and https://api.github.com/graphql. In the former, you get an array of field-value pair arrays. In the latter, you get an array of objects that reflect the actual schema of the Repository object. Which is the correct schema in this case? It seems like the latter should be, but are there guarantees that this schema is obeyed even if there are "not found" errors for some of the objects requested (as is this case in these requests).

 

Note that this is a different question from https://github.community/t5/GitHub-API-Development-and/GraphQL-v4-differences-in-responses-between-E.... There, the response value was different, but here, the response schema is different.

 

1 Reply
Solution
Community Manager
Message 2 of 2

Re: Discrepancy in schema between GraphQL Explorer and api.github.com/graphql

The Explorer is provided for quick experimentation and is not meant to be authoritative. If you want to avoid these kinds of mismatches in the future, I would recommend using GraphiQL mentioned in the GraphQL Guides.

 

I hope that helps!