Directives

circle-exclamation

Directives modify the behavior of fields, types, or operations in a GraphQL schema. They are prefixed with @ and can be applied at various locations.

Standard directives

These directives are part of the GraphQL specification and available in all queries.

@skip

Conditionally excludes a field or fragment from the response.

Argument
Type
Description

if

Boolean!

When true, the field is excluded from the response.

Locations: FIELD, FRAGMENT_SPREAD, INLINE_FRAGMENT

Example:

query GetDevice($skipCustomFields: Boolean!) {
  device(id: "123") {
    title
    customFields @skip(if: $skipCustomFields)
  }
}

@include

Conditionally includes a field or fragment in the response.

Argument
Type
Description

if

Boolean!

When true, the field is included in the response.

Locations: FIELD, FRAGMENT_SPREAD, INLINE_FRAGMENT

Example:

@deprecated

Marks a field or enum value as deprecated, signaling that it should no longer be used.

Argument
Type
Description

reason

String

Explanation of why it's deprecated and what to use instead.

Locations: FIELD_DEFINITION, ARGUMENT_DEFINITION, INPUT_FIELD_DEFINITION, ENUM_VALUE

Example:

@specifiedBy

Provides a URL to a specification that defines the behavior of a custom scalar.

Argument
Type
Description

url

String!

URL to the scalar specification document.

Locations: SCALAR

Example:

@oneOf

Indicates that an input object requires exactly one of its fields to be provided. This is useful for creating union-like input types.

Locations: INPUT_OBJECT

Example:

Custom directives

These directives are specific to the Navixy Repository API.

@trim

Automatically trims leading and trailing whitespace from string input values.

Locations: INPUT_FIELD_DEFINITION, ARGUMENT_DEFINITION

Last updated

Was this helpful?