Toggle optional fields
A client needs optional profile data without maintaining separate query documents.
GraphQL · Directive
@skip conditionally omits a field or fragment when its Boolean if argument is true. It lets one query make optional selections controlled by a literal or runtime variable.
The built-in @skip directive conditionally excludes a field or fragment from query execution when its Boolean if argument is true. Clients can provide a literal or variable value, allowing one operation to request optional data without defining separate queries.
@skip(if: Boolean)| Name | Type | Description |
|---|---|---|
if | Boolean | Boolean condition that determines whether the annotated field is skipped. |
No value is returned by the directive itself; it controls whether the annotated selection contributes to query execution and results.
query GetUser($skipBio: Boolean!) {
user(id: "1") {
id
name
bio @skip(if: $skipBio)
}
}The variable controls whether the bio field is omitted from execution.
A client needs optional profile data without maintaining separate query documents.
A feature flag determines whether experimental data should be requested.
A fragment contains data relevant only for a particular runtime condition.
@skip conditionally omits a field when its if argument evaluates to true. It is one of the two built-in executable directives that spec-compliant GraphQL servers must support.
Follow-up: How would you request the field only when a condition is true? Use @include(if: condition), which has the opposite inclusion behavior.
The directive takes a Boolean if argument and can be attached to a field or fragment inclusion. A variable is useful when the condition is supplied at runtime.
Follow-up: What happens when the variable is true? The annotated selection is skipped, so it is not included in the response data.
A client can place @skip on a field, such as bio, and pass a Boolean variable in the operation variables. The server then evaluates that condition during execution.
Follow-up: Why use this instead of separate query documents? It keeps one operation reusable while allowing optional selections to be controlled by runtime input.
@includedirectivesfieldsfragment inclusion