{"meta":{"title":"Rate limits and query limits for the GraphQL API","intro":"The GitHub GraphQL API has limitations in place to protect against excessive or abusive calls to GitHub's servers.","product":"GraphQL API","breadcrumbs":[{"href":"/en/enterprise-server@3.21/graphql","title":"GraphQL API"},{"href":"/en/enterprise-server@3.21/graphql/overview","title":"Overview"},{"href":"/en/enterprise-server@3.21/graphql/overview/rate-limits-and-query-limits-for-the-graphql-api","title":"Rate and query limits"}],"documentType":"article"},"body":"# Rate limits and query limits for the GraphQL API\n\nThe GitHub GraphQL API has limitations in place to protect against excessive or abusive calls to GitHub's servers.\n\n## Primary rate limit\n\nRate limits are disabled by default for GitHub Enterprise Server. Contact your site administrator to confirm the rate limits for your instance.\n\nIf you are a site administrator, you can set rate limits for your instance. For more information, see [Configuring rate limits](/en/enterprise-server@3.21/admin/configuring-settings/configuring-user-applications-for-your-enterprise/configuring-rate-limits).\n\nIf you are developing an app for users or organizations outside of your instance, the standard GitHub rate limits apply. For more information, see [Rate limits and query limits for the GraphQL API](/en/graphql/overview/rate-limits-and-query-limits-for-the-graphql-api) in the GitHub Free documentation.\n\n## Node limit\n\nTo pass [schema](/en/enterprise-server@3.21/graphql/guides/introduction-to-graphql#schema) validation, all GraphQL API [calls](/en/enterprise-server@3.21/graphql/guides/forming-calls-with-graphql) must meet these standards:\n\n* Clients must supply a `first` or `last` argument on any [connection](/en/enterprise-server@3.21/graphql/guides/introduction-to-graphql#connection).\n* Values of `first` and `last` must be within 1-100.\n* Individual calls cannot request more than 500,000 total [nodes](/en/enterprise-server@3.21/graphql/guides/introduction-to-graphql#node).\n\n### Calculating nodes in a call\n\nThese two examples show how to calculate the total nodes in a call.\n\n1. Simple query:\n\n   <pre>query {\n     viewer {\n       repositories(first: <span class=\"redbox\">50</span>) {\n         edges {\n           repository:node {\n             name\n\n             issues(first: <span class=\"greenbox\">10</span>) {\n               totalCount\n               edges {\n                 node {\n                   title\n                   bodyHTML\n                 }\n               }\n             }\n           }\n         }\n       }\n     }\n   }</pre>\n\n   Calculation:\n\n   <pre><span class=\"redbox\">50</span>         = 50 repositories\n    +\n   <span class=\"redbox\">50</span> x <span class=\"greenbox\">10</span>  = 500 repository issues\n\n               = 550 total nodes</pre>\n\n2. Complex query:\n\n   <pre>query {\n     viewer {\n       repositories(first: <span class=\"redbox\">50</span>) {\n         edges {\n           repository:node {\n             name\n\n             pullRequests(first: <span class=\"greenbox\">20</span>) {\n               edges {\n                 pullRequest:node {\n                   title\n\n                   comments(first: <span class=\"bluebox\">10</span>) {\n                     edges {\n                       comment:node {\n                         bodyHTML\n                       }\n                     }\n                   }\n                 }\n               }\n             }\n\n             issues(first: <span class=\"greenbox\">20</span>) {\n               totalCount\n               edges {\n                 issue:node {\n                   title\n                   bodyHTML\n\n                   comments(first: <span class=\"bluebox\">10</span>) {\n                     edges {\n                       comment:node {\n                         bodyHTML\n                       }\n                     }\n                   }\n                 }\n               }\n             }\n           }\n         }\n       }\n\n       followers(first: <span class=\"bluebox\">10</span>) {\n         edges {\n           follower:node {\n             login\n           }\n         }\n       }\n     }\n   }</code></pre>\n\n   Calculation:\n\n   <pre><span class=\"redbox\">50</span>              = 50 repositories\n    +\n   <span class=\"redbox\">50</span> x <span class=\"greenbox\">20</span>       = 1,000 pullRequests\n    +\n   <span class=\"redbox\">50</span> x <span class=\"greenbox\">20</span> x <span class=\"bluebox\">10</span> = 10,000 pullRequest comments\n    +\n   <span class=\"redbox\">50</span> x <span class=\"greenbox\">20</span>       = 1,000 issues\n    +\n   <span class=\"redbox\">50</span> x <span class=\"greenbox\">20</span> x <span class=\"bluebox\">10</span> = 10,000 issue comments\n    +\n   <span class=\"bluebox\">10</span>              = 10 followers\n\n                    = 22,060 total nodes</pre>\n\n## Query optimization strategies\n\n* **Limit the number of objects**: Use smaller values for `first` or `last` arguments and paginate through results.\n* **Reduce query depth**: Avoid requesting deeply nested objects unless necessary.\n* **Filter results**: Use arguments to filter data and return only what you need.\n* **Split large queries**: Break up complex queries into multiple simpler queries.\n* **Request only required fields**: Select only the fields you need, rather than requesting all available fields.\n\nBy following these strategies, you can reduce the likelihood of hitting resource limits and improve the performance and reliability of your API requests."}