-
Notifications
You must be signed in to change notification settings - Fork 107
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
Operation type directive is overriding directives defined in ancestor fields #242
Comments
To clarify: this bug also happens if no operation type directives were defined in the query; in that case, the overriding |
Ops, I closed by mistake. This branch in my fork deals with this issue: https://github.com/getpop/graphql-parser/tree/fix-overriding-directives |
Can you make a PR? |
Alright. I just added a test, will submit the PR now. |
The bug happens only when adding "query" at the beginning of the query: query {
user @include(if:false) {
name
}
} This query had no issue: {
user @include(if:false) {
name
}
} |
In the following query, all directives declared in the ancestor fields are lost, only the ones in the leaf fields are parsed correctly from the AST:
For instance, in this query the
@include
directive is lost, andtitle
is included when it should not:Inspecting the code, I found out that in
Parser/Parser.php
, functionparseOperation
, the operation type directive is being set into$operation
:However, the
$operation
already had its own directives, parsed throughparseBodyItem
. Hence, these are being overridden.Merging the 2 sets of directives, instead, it works well:
Is that the right solution? Must directives defined next to the operation type be copied into all ancestor fields? And what about leaf fields, which currently have no problem with their own directives? (This solution seems to fix the bug, but I don't know if I may be creating another one? I can't find any reference in the GraphQL spec to what is the expected behavior for operation type directives...)
The text was updated successfully, but these errors were encountered: