Skip to content

Instantly share code, notes, and snippets.

@phoopee3
Forked from obahareth/README.md
Last active September 14, 2019 04:22
Show Gist options
  • Save phoopee3/240c34310521c250c455755fd414582d to your computer and use it in GitHub Desktop.
Save phoopee3/240c34310521c250c455755fd414582d to your computer and use it in GitHub Desktop.
GitHub GraphQL API Starred Repositories With Pagination

GitHub GraphQL API Starred Repositories Examples With Pagination

You can play with the GraphQL API live here. It's pretty nice and has autocompletion based on the GraphQL schema.

The first example gets your first 3 starred repos, the cursor values can be used for pagination.

Here's an example response from the first query:

{
  "data": {
    "viewer": {
      "login": "obahareth",
      "name": "Omar Bahareth",
      "starredRepositories": {
        "edges": [
          {
            "cursor": "Y3Vyc29yOnYyOpLOAKYOHs4Apg4e",
            "node": {
              "id": "MDEwOlJlcG9zaXRvcnkxMjcyMzQx",
              "name": "google-spreadsheet-javascript",
              "primaryLanguage": {
                "id": "MDg6TGFuZ3VhZ2UxNDA=",
                "name": "JavaScript",
                "color": "#f1e05a"
              }
            }
          },
          {
            "cursor": "Y3Vyc29yOnYyOpLOAKYOH84Apg4f",
            "node": {
              "id": "MDEwOlJlcG9zaXRvcnk2ODEwMTQw",
              "name": "howdoi",
              "primaryLanguage": {
                "id": "MDg6TGFuZ3VhZ2UxNDU=",
                "name": "Python",
                "color": "#3572A5"
              }
            }
          },
          {
            "cursor": "Y3Vyc29yOnYyOpLOALeGxM4At4bE",
            "node": {
              "id": "MDEwOlJlcG9zaXRvcnkzNDE2MjY=",
              "name": "octopress",
              "primaryLanguage": {
                "id": "MDg6TGFuZ3VhZ2UxNDE=",
                "name": "Ruby",
                "color": "#701516"
              }
            }
          }
        ]
      }
    }
  }
}

If we add in the third cursor's value as the second example's after, we'll get the next 3 starred repositories after it.

e.g. starredRepositories(first: 3, after: "Y3Vyc29yOnYyOpLOALeGxM4At4bE")

query {
viewer {
login
name
starredRepositories(first: 3) {
edges {
cursor
node {
id
name
primaryLanguage {
id
name
color
}
}
}
}
}
}
query {
viewer {
login
name
starredRepositories(first: 3, after: "put_in_a_cursor_value_here") {
edges {
cursor
node {
id
name
primaryLanguage {
id
name
color
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment