Q15: What are `@include` and `@skip` directives?

Difficulty:EasyTopic:Directives

Directives modify query execution based on runtime conditions:

  • @include(if: Boolean): Includes a field/fragment only if the argument evaluates to true.
  • @skip(if: Boolean): Skips a field/fragment if the argument evaluates to true.
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
  • @include and @skip allow dynamic query shape changes using client variables.
Knowledge Check

What happens when `@skip(if: true)` is placed on a field?