Directive

Directives is about conditionally choosing to include a set of columns or not. We have two directives at our disposal:

  • @include, includes the fields if provided with a boolean with value true
  • @skip, does not include the fields if provided with a boolean with value true.

The reason for wanting to use such a construct is a pretty similar reason to using Fragment. Namely that we have a situation where it makes sense to get a smaller or larger payload back. Let's have a look at how we can use @include:

query MyOrders($withItems: Boolean) {
  orders {
    created,
    createdBy,
    items @include(if: $withItems)  
  }
}

Using @skip is pretty much the same as using @include but with an inverted logic:

query MyOrders($skipItems: Boolean) {
  orders {
    created,
    createdBy,
    items @skip(if: $skipItems)  
  }
}

results matching ""

    No results matching ""