Repository navigation
Avoid exponential validation of repeated fragment spreads in QueryDepth and QueryComplexity - #1996
Closed
ChiragAgg5k wants to merge 1 commit into
Closed
ChiragAgg5k wants to merge 1 commit into
ChiragAgg5k wants to merge 1 commit into
Conversation
Repeated spreads of nested fragments re-walked each fragment at every spread, making QueryDepth and QueryComplexity exponential in the nesting level.
Author
|
Closing; not pursuing this one for now. Thanks! |
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.
QueryDepthandQueryComplexityre-walk a fragment's selection set at every spread. When nested fragments spread each other more than once (F0 { ...F1 ...F1 },F1 { ...F2 ...F2 }, …), the work doubles per level, so a document of under a kilobyte can keep validation busy for seconds or longer.Both rules now compute each fragment once per validated document and reuse the result at every spread:
QueryComplexitycaches each fragment's complexity by name. Variables, and therefore@include/@skipand field arguments, are fixed for a validation run, and field definitions are resolved per AST node, so a fragment scores the same wherever it is spread. The cache is reset ingetVisitor().QueryDepthcaches each fragment's depth relative to its spread point and adds the spread depth, which gives the same result as walking it in place. Cycle detection viacalculatedFragmentsis kept; fragments found to be part of a cycle are remembered so repeated spreads into a cycle also stay linear.Tests in
QueryDepthTestandQueryComplexityTestcover a doubling-fragment document up to 50 levels (which would never finish before) with exact depth/complexity, a fragment spread at different depths,@includewith repeated spreads across variable changes, and a cycle reached through repeated spreads.Changelog
Fixed
QueryDepthandQueryComplexityfor documents that spread nested fragments repeatedly