Skip to content

Handle circular fragment references#102

Open
ivome wants to merge 2 commits into
masterfrom
handle-circular-fragment-references
Open

Handle circular fragment references#102
ivome wants to merge 2 commits into
masterfrom
handle-circular-fragment-references

Conversation

@ivome

@ivome ivome commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

Detect and skip circular fragment spreads during complexity analysis to prevent infinite recursion when evaluating invalid queries.

nodeComplexity() now tracks fragment names on the active spread path via a backtracking Set. When a fragment spread references a fragment already on that path, the spread is skipped instead of recursing indefinitely. This is a defense-in-depth measure alongside GraphQL's NoFragmentCyclesRule — graphql-js runs validation rules in parallel without early abort, so the complexity visitor could still recurse into a cycle before the cycle error is reported.

For acyclic queries, behavior is unchanged: the set is only populated during fragment descent and cleared on the way back up, so sibling spreads and diamond patterns still count correctly. The backtracking approach keeps traversal O(n) in time and memory (no per-descent Set copies).

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