@include, @skip and @deprecated GraphQL Directives

Learn how to work with @include, @skip, and @deprecated built-in GraphQL directives.

Notes

query getUsers($showName: Boolean) {
users {
id
name @include(if: $showName)
}
}
query getUsers($showName: Boolean = true) {
users {
id
name @include(if: $showName)
}
}
query getUsers($hideName: Boolean) {
users {
id
name @skip(if: $hideName)
}
}
query getUsers($excludeFields: Boolean) {
users {
id
... on User @skip(if: $excludeFields) {
name
email
role
}
}
}
fragment User on User {
name
email
role
}
query getUsers($excludeFields: Boolean) {
users {
id
...User @skip(if: $excludeFields)
}
}
type User {
id: ID!
title: String @deprecated(reason: "Use name instead")
name: String!
email: String!
role: Role
}
fragment User on User {
title @include(if: $includeDeprecatedFields)
name
email
role
}
query getUsers($includeDeprecatedFields: Boolean! = false) {
users {
id
...User
}
}
Jamie Barton

Published on 27 Sept 2021 by Jamie Barton