GraphQL Unions — Customize your results!

GraphQL Unions

Why do I need GraphQL unions?

Object type for candy
GraphQL query for candy
States of a candy – In Stock, Out of Stock and Region Unavailability
States of a candy as separate object types

How do I implement GraphQL unions?

union CandyResult = Candy | OutOfStock | RegionUnavailability

Resolving a GraphQL union (server-side):

Schema file with GraphQL union
Resolving a GraphQL union

Querying for a GraphQL union (client-side):

query {
candy(id: $id) {
... on Candy {
... on OutOfStock {
... on RegionUnavailability {
Querying with GraphQL unions

Developer & Artist