Skip to main content
Explore how the GitHub GraphQL API helps you fetch exactly the data you need, reduce network overhead, and consolidate multiple REST calls into a single request. Why switch from REST to GraphQL?
  • REST endpoints often return many fields you don’t need, increasing payload size and client-side filtering.
  • GraphQL lets you request exact fields and nested relationships in a single query, lowering bandwidth and the number of requests.
  • GraphQL exposes a rateLimit object so you can monitor query cost and remaining quota.
Example: a REST workflow runs request (returns many fields)
A sampled JSON response (abridged):
GraphQL gives you fine-grained control over the fields returned and supports nested queries, which reduces payload size and fewer HTTP requests compared to REST.
REST vs GraphQL — organization members example
  • REST (list members):
  • GraphQL (only request name and avatarUrl for the first 100 members):
Nesting and consolidating multiple REST calls into one GraphQL request If you need a pull request plus its commits, issue comments (non-review comments), and reviews, REST requires multiple endpoints:
The same data with one GraphQL query (nested):
How to call the GitHub GraphQL API Send a POST to https://api.github.com/graphql with your GraphQL query in the JSON request body. You can pass variables and include rateLimit in the query to inspect cost and remaining quota. Request example (headers):
You can place your GraphQL query directly into the JSON body. Example GraphQL query (formatted) — this requests rateLimit and one commit from the default branch:
Send that query in the JSON body along with variables:
A sample JSON response (abridged):
Understanding rate limiting and query cost
  • rateLimit.limit — total points available to your token.
  • rateLimit.cost — cost charged for the query you ran.
  • rateLimit.remaining — points left after the query.
  • rateLimit.resetAt — UTC timestamp when your limit refreshes.
Notes:
  • Simple queries frequently cost 1 point; complex nested queries often cost more.
  • Monitor rateLimit to avoid unexpectedly exhausting your quota.
Example: a complex nested query against the public Kubernetes repository This query requests repository metadata plus the first 100 pull requests, each with commits and comments — it is deep and may be costly:
Unauthenticated requests are severely rate-limited. Example error when unauthenticated:
Using a valid token raises your rate limits. Large nested queries may take longer to run and will consume more cost points — the example query above took several seconds and charged 2 points in the demo.
A screenshot of the Postman app sending a POST request to https://api.github.com/graphql, showing request headers on the left and a response timing waterfall and JSON body preview on the right.
Never commit personal access tokens or credentials to source control. For automation, use GitHub Actions secrets, environment variables, or a secrets manager and scope tokens with the least privilege required.
Best practices and additional tips
  • Request only the fields you need to minimize query cost and improve response times.
  • Use pagination (first, after) on list fields to control result size.
  • Include rateLimit in diagnostic queries to track your cost and remaining quota.
  • Cache stable data where appropriate to avoid repeated expensive queries.
  • For very large reports, consider batching queries with variables or server-side caching rather than one huge nested request.
Links and references

Watch Video