March 2018
Intermediate to advanced
304 pages
6h 59m
English
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.
union
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 |
Read now
Unlock full access