@include, @skip and @deprecated GraphQL Directives

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

Notes

1query getUsers($showName: Boolean) {
2 users {
3 id
4 name @include(if: $showName)
5 }
6}
7
1
2query getUsers($showName: Boolean = true) {
3 users {
4 id
5 name @include(if: $showName)
6 }
7}
8
1query getUsers($hideName: Boolean) {
2 users {
3 id
4 name @skip(if: $hideName)
5 }
6}
7
1query getUsers($excludeFields: Boolean) {
2 users {
3 id
4 ... on User @skip(if: $excludeFields) {
5 name
6 email
7 role
8 }
9 }
10}
11
1fragment User on User {
2 name
3 email
4 role
5}
6
7query getUsers($excludeFields: Boolean) {
8 users {
9 id
10 ...User @skip(if: $excludeFields)
11 }
12}
13
1type User {
2 id: ID!
3 title: String @deprecated(reason: "Use name instead")
4 name: String!
5 email: String!
6 role: Role
7}
8
1fragment User on User {
2 title @include(if: $includeDeprecatedFields)
3 name
4 email
5 role
6}
7
8query getUsers($includeDeprecatedFields: Boolean! = false) {
9 users {
10 id
11 ...User
12 }
13}
14