@removeNullVariables Directive

The @removeNullVariables directive allows you to remove variables with null or empty object value from your GraphQL Query or Mutation Operations.

A potential use-case could be that you have a graphql upstream which is not accepting null values for variables. By enabling this directive all variables with null values will be removed from upstream query.

1
2
3
query ($say: String, $name: String) @removeNullVariables {
hello(say: $say, name: $name)
}

The directive @removeNullVariables will transform variables json and remove top level null values.

1
{ "say": null, "name": "world" }

So upstream will receive the following variables:

1
{ "name": "world" }

The same way empty objects could be removed:

1
{ "say": {}, "name": "world" }

So upstream will receive the following variables:

1
{ "name": "world" }

Was this article helpful to you?
Provide feedback

Edit this page