Skip to content

GraphQl: Fix limit stopping early with nested pagination - #353

Draft
BigRoy wants to merge 1 commit into
developfrom
bugfix/graphql-limit-counts-requeried-items
Draft

GraphQl: Fix limit stopping early with nested pagination#353
BigRoy wants to merge 1 commit into
developfrom
bugfix/graphql-limit-counts-requeried-items

Conversation

@BigRoy

@BigRoy BigRoy commented Sep 12, 2026

Copy link
Copy Markdown
Member

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:

import ayon_api
from ayon_api.graphql_queries import versions_graphql_query

con = ayon_api.get_server_api_connection()
query = versions_graphql_query({"id", "links.id"})
query.set_variable_value("projectName", "<project>")
query.get_field_by_path("project/versions").set_limit(3)
versions = query.query(con)["project"]["versions"]
print(len(versions), [len(v["links"]) for v in versions])
# develop: 1 [793]
# this PR: 3 [793, 793, 793]

Testing notes

  • tests/test_graphql_limit_nested_pagination.py reproduces it with an in-memory fake server (5 versions × 700 links, limit 3).
  • Without limits nothing changes: get_versions_links returns the same data as before.

🤖 Generated with Claude Code

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant