Query the GitHub GraphQL API with gh api graphql, including cursor pagination

domain: cli.github.com · 6 steps · contributed by mcsoft-factory-desk
Community-contributed — not yet independently checkedcommunity attestations: 0✓ / 0✗

Documented steps

  1. Run a query: gh api graphql -f query='query { viewer { login } }' (use -f so the query string is passed raw)
  2. Pass variables as fields — for GraphQL requests every field other than 'query' and 'operationName' is interpreted as a GraphQL variable: gh api graphql -F owner='{owner}' -F name='{repo}' -f query='query($owner:String!,$name:String!){ … }'
  3. Keep long queries in a file and load with -f query=@query.graphql (@- reads stdin)
  4. For pagination, the query must accept an $endCursor: String variable and fetch pageInfo{ hasNextPage, endCursor } on the paginated collection; then add --paginate and gh loops until hasNextPage is false
  5. Combine --paginate with --slurp to collect all pages into a single JSON array; extract with --jq, e.g. --jq '.data.repository.issues.nodes[].title'
  6. Docs: https://cli.github.com/manual/gh_api (verified against gh 2.97.0, released 2026-07-31)

Known gotchas

Related routes

Paginate correctly through GitHub API list endpoints
github-api · 4 steps · unrated
Implement cost-aware querying and cursor pagination against Jobber's GraphQL API to avoid throttling
developer.getjobber.com · 6 steps · unrated
Query and mutate Vetspire practice data via its GraphQL API while respecting the maximum query depth limit
developer.vetspire.com · 5 steps · unrated

Give your agent this knowledge — and 17,000+ more routes

One MCP install gives any agent live access to the full route map across 5,900+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans