graph-quilt / graph-quilt/graphql-orchestrator-java

Always forward @include & @skip directive with variable reference to downstream

Open
#169 2 comments 0 reactions 1 assignee Claimed by @kulkarnianiket View on GitHub
enhancement hacktoberfest hacktoberfest2023
Dominant language
Groovy
Stars
73
Forks
32
PR merge metrics
No merged PRs in 30d

Description

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](https://graphql.org/learn/queries/#directives).

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](https://github.com/graph-quilt/graphql-orchestrator-java/blob/master/src/main/java/com/intuit/graphql/orchestrator/batch/GraphQLServiceBatchLoader.java#L209)). This is because the [QueryTraverser.java](https://github.com/graphql-java/graphql-java/blob/master/src/main/java/graphql/analysis/QueryTraverser.java#L44) used in [VariableDefinitionFilter.java](https://github.com/graph-quilt/graphql-orchestrator-java/blob/master/src/main/java/com/intuit/graphql/orchestrator/batch/VariableDefinitionFilter.java#L44) 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](https://github.com/graph-quilt/graphql-orchestrator-java/blob/master/src/main/java/com/intuit/graphql/orchestrator/batch/VariableDefinitionFilter.java#L44). See an example implementation [here](https://github.com/graph-quilt/graphql-orchestrator-java/blob/master/src/main/java/com/intuit/graphql/orchestrator/batch/AuthDownstreamQueryModifier.java#L65).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.