Key links

Uncategorized Links

  • GraphQL explorer
    • Online tool - “Start exploring GraphQL API queries using your account’s data now.”
  • Using the explorer
    • GraphiQL explorer for use in browser - run queries, use hints, get validation and learn about the schema
  • Forming Calls with GraphQL
    • Authenticate and send POST requests to api.github.com/graphql
  • Reference
  • Developers
    • Go deeper with GitHub by integrating with our APIs, customizing your GitHub workflow, and building and sharing apps with the community.

My projects

You can use the GitHub GraphQL API to create precise and flexible queries for the data you need to integrate with GitHub.

I have a couple of examples of GQL queries as gists - see my Gist viewer.

API endpoint

Do authenticated POST requests here.

  • https://api.github.com/graphql

Using cURL, Python/Node script or server, Insomnia/Postman, a Lambda, etc.

Avoid doing frontend queries as you then have to expose your token in the browser to users who can abuse it.

Cursors in GraphQL

A GraphQL endpoint will limit how many items it returns to you on a page, to prevent abuse caused by requesting too many items at once.

After the first query, if there is a second page to fetch then you’ll get a 'hasNextPage' value in the paging data as true. And you’ll get an 'endCursor' value. Pass this cursor value in the query params payload to tell the API to skip the first page.

Then get the cursor on the second page’s request and pass it to on the third request, as so on.

The cursor is temporary and specific to a query and should not be reused (such as copy and pasted by hand for long term use). It is intentionally opaque as a hashed value. In the case of GitHub, the hashed value component is followed by a space and number at the end. The number indicates the index of the last item on the current page, using zero based indexing.

For example:

  1. Do query for page 1 with 100 items. No cursor sent.
  2. Page 1 data received. Paging data includes an end cursor as something like this: 9eee3f4054dd502b105626632b15d01038a95aae 99.
  3. Do query for page 2 with 100 items. Send cursor from step above.
  4. Page 2 data received. Paging data includes an end cursor as something like this: 9eee3f4054dd502b105626632b15d01038a95aae 199.
  5. Do query for page 3 and so on.