Union
- Description
-
Represents an object that could be one of a list of GraphQL object types, but provides for no guaranteed fields between those types. They also differ from interfaces in that object types declare what interfaces they implement, but are not aware of what unions contain them.
- Absinthe Macro
-
union
Examples
In an Absinthe schema, defining the union and mapping results to the associated GraphQL type:
â | @desc â"ââA search result"â |
â | union â:search_resultâ âdoâ |
â | types [â:personâ, â:businessâ] |
â | resolve_type âfnâ |
â | %Person{}, _ -> |
â | â:personâ |
â | %Business{}, _ -> |
â | â:businessâ |
â | _, _ -> |
â | nil |
â | âendâ |
â | âendâ |
Get Craft GraphQL APIs in Elixir with Absinthe now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.