为何在GitHub GraphQL API中重复调用字段可绕过分页限制?
Great catch! This is a specific behavior of the GitHub GraphQL API's pagination rules, and it makes sense once you break down what's happening in each query:
Let's unpack the two queries
First query (throws pagination error)
Your first query only asks for thenodeslist from therepositoriesconnection, with no other metadata about that connection:query { user(login:"armsp"){ repositories{ nodes{ name issues(states: OPEN){ totalCount } } } } }GitHub's API enforces strict pagination here because you're only requesting list data — it wants you to explicitly set
firstorlastto limit how many results you fetch, which prevents accidental large requests that could overload their servers.Second query (works without explicit pagination)
In your second query, you're making two separate calls to therepositoriesconnection under the same user:query { user(login:"armsp"){ repositories{ totalCount } repositories{ nodes{ name issues(states: OPEN){ totalCount } } } } }When you include a request for
totalCount(a single value, not a list) alongside yournodesrequest, the API relaxes its strict pagination check for thenodeslist. Instead of throwing an error, it automatically returns up to 100 results (GitHub's default limit for connection fields when you don't specifyfirst/last).
A critical clarification: You're not getting "all" results
If armsp has more than 100 repositories, your second query will only return the first 100. The API still limits the result set — it just doesn't force you to explicitly define that limit in this scenario. To fetch every repository, you'd still need to implement proper pagination using first/last paired with after/before cursors.
Test this yourself to confirm
- If you remove the
repositories{ totalCount }line from your second query, it will immediately throw the sameMISSING_PAGINATION_BOUNDARIESerror as your first query. - If you run the second query for a user with over 100 repositories, you'll see the
nodesarray cuts off at 100 entries.
内容的提问来源于stack exchange,提问作者jar

