-
-
Notifications
You must be signed in to change notification settings - Fork 566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Query complexity is missing on fields included by fragments #785
Comments
@spawnia Any thoughts on this? We were only able to fix the issue when we introduced deep changes to the way this class works, like only handling |
For many complex implementations, we use |
When i get it right then you can fix the mentioned issue at least with that easy workaround: $parser = Parser::parse($input['query']);
$newDefinitions = [];
foreach ($parser->definitions as $def) {
if ($def->kind === NodeKind::FRAGMENT_DEFINITION) {
array_unshift($newDefinitions, $def);
} else {
array_push($newDefinitions, $def);
}
}
$parser->definitions = $newDefinitions;
$rule = new QueryComplexity($maxQueryComplexity);
$parseErrors = DocumentValidator::validate(
$schema,
$parser,
array_merge(DocumentValidator::defaultRules(), [$rule])
); When that has no side effects, would that not be a option for the base-framework to put them always on top? |
First step towards fixing this is adding a failing test case to https://github.com/webonyx/graphql-php/blob/master/tests/Validator/QueryComplexityTest.php. |
Description
QueryComplexity
rule implements visitor in such a way that results in missing field definitions when non-inline fragments are used and defined after the operation (as it usually is). If you reverse the order and put fragments first, all works fine.Reproduction path
A simple reproduction script is attaching a custom complexity closure to
ExampleType
fields. They are included using a fragment, and should result in a complexity error. However, no such error is triggered, because these field definitions are missing fromfieldNodeAndDefs
, and a default complexity function is used on them.Put it in an empty directory, call
composer require webonyx/graphql-php
and runphp complexity.php
.The text was updated successfully, but these errors were encountered: