# Rate limits and query limits for the GraphQL API

The GitHub GraphQL API has limitations in place to protect against excessive or abusive calls to GitHub's servers.

## Primary rate limit

Rate limits are disabled by default for GitHub Enterprise Server. Contact your site administrator to confirm the rate limits for your instance.

If you are a site administrator, you can set rate limits for your instance. For more information, see [Configuring rate limits](/en/enterprise-server@3.22/admin/configuring-settings/configuring-user-applications-for-your-enterprise/configuring-rate-limits).

If 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.

## Node limit

To pass [schema](/en/enterprise-server@3.22/graphql/guides/introduction-to-graphql#schema) validation, all GraphQL API [calls](/en/enterprise-server@3.22/graphql/guides/forming-calls-with-graphql) must meet these standards:

* Clients must supply a `first` or `last` argument on any [connection](/en/enterprise-server@3.22/graphql/guides/introduction-to-graphql#connection).
* Values of `first` and `last` must be within 1-100.
* Individual calls cannot request more than 500,000 total [nodes](/en/enterprise-server@3.22/graphql/guides/introduction-to-graphql#node).

### Calculating nodes in a call

These two examples show how to calculate the total nodes in a call.

1. Simple query:

   <pre>query {
     viewer {
       repositories(first: <span class="redbox">50</span>) {
         edges {
           repository:node {
             name

             issues(first: <span class="greenbox">10</span>) {
               totalCount
               edges {
                 node {
                   title
                   bodyHTML
                 }
               }
             }
           }
         }
       }
     }
   }</pre>

   Calculation:

   <pre><span class="redbox">50</span>         = 50 repositories
    +
   <span class="redbox">50</span> x <span class="greenbox">10</span>  = 500 repository issues

               = 550 total nodes</pre>

2. Complex query:

   <pre>query {
     viewer {
       repositories(first: <span class="redbox">50</span>) {
         edges {
           repository:node {
             name

             pullRequests(first: <span class="greenbox">20</span>) {
               edges {
                 pullRequest:node {
                   title

                   comments(first: <span class="bluebox">10</span>) {
                     edges {
                       comment:node {
                         bodyHTML
                       }
                     }
                   }
                 }
               }
             }

             issues(first: <span class="greenbox">20</span>) {
               totalCount
               edges {
                 issue:node {
                   title
                   bodyHTML

                   comments(first: <span class="bluebox">10</span>) {
                     edges {
                       comment:node {
                         bodyHTML
                       }
                     }
                   }
                 }
               }
             }
           }
         }
       }

       followers(first: <span class="bluebox">10</span>) {
         edges {
           follower:node {
             login
           }
         }
       }
     }
   }</code></pre>

   Calculation:

   <pre><span class="redbox">50</span>              = 50 repositories
    +
   <span class="redbox">50</span> x <span class="greenbox">20</span>       = 1,000 pullRequests
    +
   <span class="redbox">50</span> x <span class="greenbox">20</span> x <span class="bluebox">10</span> = 10,000 pullRequest comments
    +
   <span class="redbox">50</span> x <span class="greenbox">20</span>       = 1,000 issues
    +
   <span class="redbox">50</span> x <span class="greenbox">20</span> x <span class="bluebox">10</span> = 10,000 issue comments
    +
   <span class="bluebox">10</span>              = 10 followers

                    = 22,060 total nodes</pre>

## Query optimization strategies

* **Limit the number of objects**: Use smaller values for `first` or `last` arguments and paginate through results.
* **Reduce query depth**: Avoid requesting deeply nested objects unless necessary.
* **Filter results**: Use arguments to filter data and return only what you need.
* **Split large queries**: Break up complex queries into multiple simpler queries.
* **Request only required fields**: Select only the fields you need, rather than requesting all available fields.

By following these strategies, you can reduce the likelihood of hitting resource limits and improve the performance and reliability of your API requests.