GitHub REST and GraphQL: Pagination and Response Shapes
Select the API interface
REST exposes resource endpoints with HTTP methods and response status and headers. GraphQL queries request selected fields through a schema; mutations can modify resources. A GraphQL query can use HTTP POST while remaining a read operation. Check the endpoint documentation and supported API version rather than inferring permissions from HTTP verbs alone.
Follow REST pagination
A page of results is not the complete collection. GitHub REST pagination uses Link relations where supported. Follow the provided next relation until it is absent; validate the destination host and preserve authorization boundaries. The mock pages contain two records then one. The REST issues endpoint may include pull requests; use the dedicated pulls endpoint or filter records with a pull_request field when counting issues. Adding field flags to gh api can change the default method to POST; explicitly select GET for this REST read. The slurp option wraps pages in an outer array, not a flat issue list.
gh api --method GET 'repos/OWNER/REPO/issues?per_page=2' --paginate --slurpFollow GraphQL cursors
For a connection, request nodes plus pageInfo. Pass endCursor into the next request while hasNextPage is true; stop on false. Cursors are opaque, not page numbers. An HTTP 200 response can still contain errors or partial data: do not silently count a partial response as complete. The example uses a fictional repository and is not executed here.
gh api graphql --paginate --slurp -f query='query($endCursor: String) { repository(owner: "OWNER", name: "REPO") { issues(first: 2, after: $endCursor) { nodes { number title } pageInfo { hasNextPage endCursor } } }}'Check completeness
The offline fixture supplies already-decoded next relations rather than implementing an HTTP Link parser. It validates page shape and host, detects cycles, enforces a page budget and rejects GraphQL errors or missing cursors. Both successful walks return [12, 14, 16]. This is a deterministic snapshot; live pages can change while traversing, so exact counts may need a separate consistency strategy.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
GitHub REST and GraphQL: Pagination and Response Shapes — knowledge check
Reason about GitHub CLI and API response handling.
What signals another REST page?
When does a GraphQL connection walk finish?
What if GraphQL returns data and errors with HTTP 200?
What is an endCursor?
What can the REST issues endpoint also include?