absinthe v0.4.5 Absinthe.Type.Union

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
@absinthe :type
def search_result do
  %Type.Union{
    description: "A search result that can be a person or business",
    types: [:person, :business],
    resolve_type: fn
      %{age: _}, _ -> {:ok, :person}
      %{employee_count: _}, _ -> {:ok, :business}
      _ -> :error
    end
  }
end
  • :name - The name of the union type. Should be a TitleCased binary. Set automatically when using @absinthe :type from Absinthe.Type.Definitions.
  • :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 also Absinthe.Type.Object’s :is_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 :reference key is for internal use.

Summary

Functions

Callback implementation for c:Absinthe.Introspection.Kind.kind/0

Types

t :: %{name: binary, description: binary, types: [Absinthe.Type.t], resolve_type: (any, Absinthe.Execution.t -> atom | nil), reference: Absinthe.Type.Reference.t}

Functions

kind()

Callback implementation for c:Absinthe.Introspection.Kind.kind/0.