Skip to content
GraphQL

Directives

Conditionally include or skip fields.

#directive#include#skip

Code

graphql
query GetUser($id: ID!, $withPosts: Boolean!) {
  user(id: $id) {
    id
    name
    posts @include(if: $withPosts) {
      title
    }
    email @skip(if: true)
  }
}

# Custom directive declaration
directive @deprecated(reason: String) on FIELD_DEFINITION

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