Absinthe.Type.Union (absinthe v1.6.4) View Source
A unions is an abstract type made up of multiple possible concrete types.
No common fields are declared in a union. Compare to Absinthe.Type.Interface
.
Because it's necessary for the union to determine the concrete type of a resolved object, you must either:
- Provide a
:resolve_type
function on the union - Provide a
:is_type_of
function on each possible concrete type
union :search_result do
description "A search result"
types [:person, :business]
resolve_type fn
%Person{}, _ -> :person
%Business{}, _ -> :business
end
end
Link to this section Summary
Types
:name
- The name of the union type. Should be a TitleCasedbinary
. Set automatically.:description
- A nice description for introspection.:types
- The list of possible types.:resolve_type
- A function used to determine the concrete type of a resolved object. See alsoAbsinthe.Type.Object
's:is_type_of
. Eitherresolve_type
is specified in the union type, or every object type in the union must specifyis_type_of
The :resolve_type
function will be passed two arguments; the object whose type needs to be identified, and the Absinthe.Execution
struct providing the full execution context.
Link to this section Types
Specs
t() :: %Absinthe.Type.Union{ __private__: Keyword.t(), __reference__: Absinthe.Type.Reference.t(), definition: module(), description: binary(), fields: map(), identifier: atom(), name: binary(), resolve_type: term(), types: [Absinthe.Type.identifier_t()] }
:name
- The name of the union type. Should be a TitleCasedbinary
. Set automatically.:description
- A nice description for introspection.:types
- The list of possible types.:resolve_type
- A function used to determine the concrete type of a resolved object. See alsoAbsinthe.Type.Object
's:is_type_of
. Eitherresolve_type
is specified in the union type, or every object type in the union must specifyis_type_of
The :resolve_type
function will be passed two arguments; the object whose type needs to be identified, and the Absinthe.Execution
struct providing the full execution context.
The __private__
and :__reference__
keys are for internal use.
Link to this section Functions
Callback implementation for c:Absinthe.Introspection.TypeKind.kind/0
.