absinthe v0.4.4 Absinthe.Type.Interface
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
it guarantees that it defines the same fields and arguments that the
interface does.
Because sometimes it’s necessary 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
@absinthe :type
def named_entity do
%Type.Interface{
fields: fields(
name: [type: :string]
),
resolve_type: fn
%{age: _}, _ -> {:ok, :person}
%{employee_count: _}, _ -> {:ok, :business}
_ -> :error
end
}
end
@absinthe :type
def person do
%Type.Object{
fields: fields(
name: [type: :string],
age: [type: :string]
),
interfaces: [:named_entity]
}
end
@absinthe :type
def business do
%Type.Object{
fields: fields(
name: [type: :string],
employee_count: [type: :integer]
),
interfaces: [:named_entity]
}
end
:name
- The name of the interface type. Should be a TitleCasedbinary
. Set automatically when using@absinthe :type
fromAbsinthe.Type.Definitions
.:description
- A nice description for introspection.:fields
- A map ofAbsinthe.Type.Field
structs. SeeAbsinthe.Type.Definitions.fields/1
and:args
- A map ofAbsinthe.Type.Argument
structs. SeeAbsinthe.Type.Definitions.args/1
.:resolve_type
- A function used to determine the implementing type of a resolved object. See alsoAbsinthe.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, fields: map, resolve_type: (any, Absinthe.Execution.t -> atom | nil), reference: Absinthe.Type.Reference.t}
Functions
Specs
implements?(Absinthe.Type.Interface.t, Absinthe.Type.Object.t) :: boolean
Specs
resolve_type(Absinthe.Type.Interface.t, any, Absinthe.Execution.t) ::
Absinthe.Type.t |
nil