I have Major categories and Minor Categories that belong to a Major category. Both are ENUM type. I want client to choose matching minor category ENUM to submit with its Major category. I don't want to include all different minor category ENUMs as fields.
I first tried doing
union MinorCategories = Minor1 | Minor2
However this failed because union
only works with ObjectTypes
Enforcing minor category depending on the major category is not necessary. I only want to receive one field that can be selective by the client by ENUM. Is there any work around?
GraphQL does not support union types for scalar values, only for object types. One option, albeit an ugly one, is to wrap your enums in an object type.
type Minor1Wrapper {
value: Minor1!
}
type Minor2Wrapper {
value: Minor2!
}
union MinorCategories = Minor1Wrapper | Minor2Wrapper
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With