4

The GraphQL specification allows us to add custom query directives. I'm looking for some information on how can I do this. I want to create a @include like a directive, but with more elaborate logic.

Apollo guide describes only adding scheme (i.e. working on the server) directive.

Federico Navarrete
  • 3,069
  • 5
  • 41
  • 76
s-f
  • 2,091
  • 22
  • 28

1 Answers1

-1

The @include directive can be used to include a field based on the value of the if argument. The query below would only include the authors for a post if includeAuthor GraphQL variable has a value true.

GraphQL Query

query ($includeAuthor: Boolean!) {
    queryPost {
    id
    title
    text
    author @include(if: $includeAuthor) {
        id
        name
    }
  }
}

GraphQL variables

{
   "includeAuthor": false
}
Federico Navarrete
  • 3,069
  • 5
  • 41
  • 76
Ankit
  • 1
  • 1