Skip to content
Advertisement

How to define Nested enum type in GraphQL schema

I have an enum defined in graphql schema as below:

JavaScript

But the WILDCARD query, can be further specified as STARTSWITH, ENDSWITH and CONTAINS,

So can we achieve something like below while defining Schema

JavaScript

or

JavaScript

Advertisement

Answer

There are no such nested enums in GraphQL schema. You can consider to model it using two separate fields with separate enums .

JavaScript

And suppose an object type call SearchQuery need to contains these info . Its schema may look likes:

JavaScript

wildcardType is an optional field which only contains the value if the queryType is WILDCARD. Otherwise , it should be null.

Alternatively you can also consider to model it to be more ‘polymorphism’ style using the interface. Something likes :

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement