GraphQl: Fix limit stopping early with nested pagination - #353
Draft
BigRoy wants to merge 1 commit into
Draft
Conversation
While a nested edge field needs more pages, the same parent item is queried again. Every re-query added the parent item to the fetched counter again, so the limit was reached before enough items were received. Count only items that were not received before. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
When an edge field has a limit (
set_limit) and it also has a nested edge field (e.g.links), fewer items than the limit are returned whenever a nested field needs more than one page.Example: versions limited to 3, each with 700 links → only 1 version is returned.
Cause
Nested edge fields can't be paged for multiple parents at once, so the parent item is queried again (same cursor) until its nested field is fully fetched.
_fetched_counter += len(edges)ran on each of those re-queries, so the same parent was counted once per nested page (700 links = 3 pages = counted 3 times) and the limit was reached after the first parent.Fix
Count only items that were newly added to the output (
len(node_values)before/after parsing the page). Re-parsed items are already merged by cursor, so they don't increase the count.Reproduce
No public helper currently sets a limit together with nested edge fields, so this is reproduced with a custom query. Requires a project where the first versions have more than 300 links:
Testing notes
tests/test_graphql_limit_nested_pagination.pyreproduces it with an in-memory fake server (5 versions × 700 links, limit 3).get_versions_linksreturns the same data as before.🤖 Generated with Claude Code