1
votes

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?

Thanks!

1

1 Answers

1
votes

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