HomeToolsAbout

Directives

What is it

Directives are used to provide information to the server about how a query or mutation should be executed

Decorates part of a GQL schema or operation (query/mutation) with additional configuration

type ExampleType { oldField: String @deprecated(reason: "Use `newField`") newField: String }

@include

Only returns the record on a field when the return value from the resolver passes the defined condition.

The field resolver won't run when the condition is not met.

query getUsers { users { id name @include(if: false) email role } }

The query would not return the name field unless the value is true.

  • When it is set to false, it would have same effect as a skip.

@skip

Using the @skip directive, skipped based on the value of the if argument.

query ($skipTitle: Boolean!) { queryPost { id title @skip(if: $skipTitle) text } } # variable { "skipTitle": true }

@deprecated

Marks a field or enum value as deprecated, providing information about why it is deprecated.

type User { username: String password: String @deprecated(reason: "Use more secure authentication methods.") }

Custom Directives

directive @customDirective(arg: String) on FIELD type Query { exField: String @customDirective(arg: "exField") }
AboutContact