fix(graphql-limit-count): measure each fragment once when computing query depth - #13809
Open
shreemaan-abhishek wants to merge 2 commits into
Open
fix(graphql-limit-count): measure each fragment once when computing query depth#13809shreemaan-abhishek wants to merge 2 commits into
shreemaan-abhishek wants to merge 2 commits into
Conversation
AlinsRan
approved these changes
Aug 13, 2026
nic-6443
approved these changes
Aug 13, 2026
membphis
reviewed
Aug 13, 2026
membphis
left a comment
Member
There was a problem hiding this comment.
[P2] Fragment memoization caches a cycle-context-dependent depth
memo is keyed only by fragment name, but the cached depth also depends on the current visited recursion stack. With mutually recursive fragments, the first traversal can cache an incomplete depth and reuse it from another path, making the computed cost traversal-order-dependent and potentially undercounting quota usage.
Please avoid memoizing cycle-dependent results, for example by excluding cyclic fragment components from memoization or rejecting cyclic fragment graphs, and add regression tests for mutually recursive fragments reached at different nesting depths and in different traversal orders.
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.
Description
graphql-limit-countcomputes a query's selection-nesting depth (used as the rate-limit cost) by expanding fragment spreads in place. The cycle guard (visited) was cleared after each descent, so a fragment referenced from more than one place was fully re-measured on every occurrence. When fragments reference other fragments repeatedly, the depth computation grows exponentially in the number of fragments, so a small document can become expensive to process in the access phase.This memoizes each fragment's resolved depth so a fragment is measured once regardless of how many times it is spread.
visitedstill guards fragment cycles; a newmemotable caches the per-fragment result, keeping the traversal linear in the document size. The computed depth is unchanged for existing queries.Added tests: a route whose query reuses fragments many times now returns normally instead of stalling the worker.
Which issue(s) this PR fixes:
Checklist