Repository navigation
fix: leave invalid variables to the executor under limitQueryComplexity() - #839
Merged
oojacoboo merged 3 commits intoOct 11, 2026
Conversation
…ty() webonyx's QueryComplexity rule coerces the operation's variables while pricing fields by their arguments, and throws a single error joining every coercion message, without locations. That preempts the executor, which refuses the same variables with one located error per variable. limitQueryComplexity() now registers TheCodingMachine\GraphQLite\Validator\Rules\QueryComplexity, a subclass that wraps the parent's document visitor: when the variables really fail coercion it reports nothing and the executor refuses them; any other error is rethrown, so the limit holds.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #839 +/- ##
============================================
- Coverage 95.72% 92.06% -3.67%
- Complexity 1773 2169 +396
============================================
Files 154 205 +51
Lines 4586 5772 +1186
============================================
+ Hits 4390 5314 +924
- Misses 196 458 +262 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Problem
Psr15GraphQLMiddlewareBuilder::limitQueryComplexity()registers webonyx'sQueryComplexityrule. To price fields by their arguments, that rule coerces the operation's variables during validation (Values::getVariableValues()inbuildFieldArguments()anddirectiveExcludesField()). When a variable fails coercion, for example a custom scalar'sparseValue()refusing a value, it throws oneErrorwhose message joins every coercion message with"\n\n", without locations.That preempts the executor, which would refuse the same variables a moment later (CoerceVariableValues, before any resolver runs) with one error per variable, each with its location and the usual
Variable "$x" got invalid value ...message. So any server usinglimitQueryComplexity()loses per-variable coercion errors.Fix
TheCodingMachine\GraphQLite\Validator\Rules\QueryComplexityextends webonyx's rule (it has to stay a subclass, sinceGraphQL::promiseToExecute()only hands raw variables toinstanceof QueryComplexityrules) and wraps the parent'sDocumentleave callback:GraphQL\Error\Error, it checks whether the raw variables really fail coercion against the document's variable definitions. If they do, it reports nothing and the executor refuses them per variable. Otherwise it rethrows, so an unrelated error can't disable the limit.limitQueryComplexity()now registers this rule. Users who add webonyx's rule withaddValidationRule()can switch to this class.Forward compatibility
Only public webonyx API is used:
getVisitor(),getRawVariableValues(),Values::getVariableValues()and the public AST. If a future webonyx version stops exposing aDocumentleave callback, the parent visitor is returned unchanged, which degrades to today's behavior.Tests
Errorthrown while pricing is not swallowed.Intvariable.