romeboards
romeboards

Reputation: 397

GraphQL: creating directives with string comparison

I'm looking to create a GraphQL query that selectively adds/removes fields based on a variable "type", which is a string:

query ResultsPage($casetype: String!)

According to the reference on Directives, you can use a boolean value to either @include or @skip certain fields:

query Hero($episode: Episode, $withFriends: Boolean!) {
  hero(episode: $episode) {
    name
    friends @include(if: $withFriends) {
      name
    }
  }
}

How could I do something similar with this string value? i.e. only include the friends field if $casetype = "foo". Is this possible with GraphQL?

Upvotes: 1

Views: 2600

Answers (1)

Harut Margaryan
Harut Margaryan

Reputation: 96

Unfortunately there is no way to use string comparison. Only way that you can is write custom Directive which can handle on its own.

please check a closed issue here

Upvotes: 1

Related Questions