Skip to content

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

@bhavinshah7

Description

@bhavinshah7

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.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions