graphql-orchestrator-java
graphql-orchestrator-java copied to clipboard
Always forward @include & @skip directive with variable reference to downstream
The core GraphQL specification includes the following directives:
@include(if: Boolean)Only include this field in the result if the argument is true.@skip(if: Boolean)Skip this field if the argument is true.
More info about graphql directives in general here.
In graphql-orchestrator-java, we want these directives to be always included in the downstream query.
Problem
The @include and @skip are not passed to downstream for the following scenarios:
| Directive | Current Behavior | Expected |
|---|---|---|
| @include(if: $var) | if var = false, directive is not included in the downstream query. | include in downstream query |
| @skip(if: $var) | if var = true, directive is not included in the downstream query. | include in downstream query |
Why:
The directives are not added to the list that needs to be included in the downstream query. (see Code). This is because the QueryTraverser.java used in VariableDefinitionFilter.java evaluates the arguments and ignores accordingly. (The QueryTraverser.java JavaDoc explains this as well)
Solution:
We did not find a way to change the behavior of QueryTraverser.java. As an alternative, implement a NodeVisitor and use in VariableDefinitionFilter.java. See an example implementation here.
Hey @bhavinshah7 , I would like to work on this. Thanks
@kulkarnianiket assigned the story to you. Feel free to reach out if you need help.