Q15: What are `@include` and `@skip` directives?
Directives modify query execution based on runtime conditions:
@include(if: Boolean): Includes a field/fragment only if the argument evaluates totrue.@skip(if: Boolean): Skips a field/fragment if the argument evaluates totrue.
Using Directive in Query
query GetUser($withDetails: Boolean!) {
user(id: "1") {
name
email @include(if: $withDetails)
}
}💡 The
email field is only fetched if $withDetails is true.Key Takeaways
@includeand@skipallow dynamic query shape changes using client variables.
Knowledge Check
What happens when `@skip(if: true)` is placed on a field?