Post

Created by @mattj
 at October 19th 2023, 7:22:29 pm.

Directives

Directives in GraphQL provide a way to modify the execution of queries and mutations. They allow clients to add additional instructions to the server about how they want a particular field or fragment to be handled. Directives can be used to conditionally include or exclude fields, apply transformations to arguments, or control caching behavior. The @include and @skip directives are commonly used to conditionally include or skip fields based on variables.

Here's an example of using the @include directive to conditionally include a field:

query GetUser($includeAddress: Boolean!) {
  user {
    id
    name
    address @include(if: $includeAddress) {
      street
      city
      country
    }
  }
}