View Source Absinthe.Type.Interface (absinthe v1.7.0)

A defined interface type that represent a list of named fields and their arguments.

Fields on an interface have the same rules as fields on an Absinthe.Type.Object.

If an Absinthe.Type.Object lists an interface in its :interfaces entry, it guarantees that it defines the same fields and arguments that the interface does.

Because sometimes it's for the interface to determine the implementing type of a resolved object, you must either:

  • Provide a :resolve_type function on the interface
  • Provide a :is_type_of function on each implementing type
interface :named_entity do
  field :name, :string
  resolve_type fn
    %{age: _}, _ -> :person
    %{employee_count: _}, _ -> :business
    _, _ -> nil
  end
end

object :person do
  field :name, :string
  field :age, :string

  interface :named_entity
end

object :business do
  field :name, :string
  field :employee_count, :integer

  interface :named_entity
end

Link to this section Summary

Types

t()

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.

Functions

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

Whether the interface (or implementors) are correctly configured to resolve objects.

Link to this section Types

Specs

t() :: %Absinthe.Type.Interface{
  __private__: Keyword.t(),
  __reference__: Absinthe.Type.Reference.t(),
  definition: module(),
  description: binary(),
  fields: map(),
  identifier: atom(),
  interfaces: [t()],
  name: binary(),
  resolve_type: term()
}

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.

Link to this function

resolve_type(type, obj, env, opts \\ [lookup: true])

View Source
Link to this function

type_resolvable?(schema, iface)

View Source

Specs

type_resolvable?(Absinthe.Schema.t(), t()) :: boolean()

Whether the interface (or implementors) are correctly configured to resolve objects.