View Source Absinthe.Type.Object (absinthe v1.7.0)
Represents a non-leaf node in a GraphQL tree of information.
Objects represent a list of named fields, each of which yield a value of a specific type. Object values are serialized as unordered maps, where the queried field names (or aliases) are the keys and the result of evaluating the field is the value.
Also see Absinthe.Type.Scalar
.
Examples
Given a type defined as the following (see Absinthe.Schema.Notation.object/3
):
@desc "A person"
object :person do
field :name, :string
field :age, :integer
field :best_friend, :person
field :pets, list_of(:pet)
end
The "Person" type (referred inside Absinthe as :person
) is an object, with
fields that use Absinthe.Type.Scalar
types (namely :name
and :age
), and
other Absinthe.Type.Object
types (:best_friend
and :pets
, assuming
:pet
is an object).
Given we have a query that supports getting a person by name
(see Absinthe.Schema
), and a query document like the following:
{
person(name: "Joe") {
name
best_friend {
name
age
}
pets {
breed
}
}
}
We could get a result like this:
%{
data: %{
"person" => %{
"best_friend" => %{
"name" => "Jill",
"age" => 29
},
"pets" => [
%{"breed" => "Wyvern"},
%{"breed" => "Royal Griffon"}
]
}
}
}
Link to this section Summary
Link to this section Types
Specs
t() :: %Absinthe.Type.Object{ __private__: Keyword.t(), __reference__: Absinthe.Type.Reference.t(), definition: module(), description: binary(), fields: map(), identifier: atom(), interfaces: [Absinthe.Type.Interface.t()], is_type_of: term(), name: binary() }
A defined object type.
Note new object types (with the exception of the root-level query
, mutation
, and subscription
)
should be defined using Absinthe.Schema.Notation.object/3
.
:name
- The name of the object type. Should be a TitleCasedbinary
. Set automatically.:description
- A nice description for introspection.:fields
- A map ofAbsinthe.Type.Field
structs. Usually built viaAbsinthe.Schema.Notation.field/4
.:interfaces
- A list of interfaces that this type guarantees to implement. SeeAbsinthe.Type.Interface
.:is_type_of
- A function used to identify whether a resolved object belongs to this defined type. For use with:interfaces
entry andAbsinthe.Type.Interface
. This function will be passed one argument; the object whose type needs to be identified, and should returntrue
when the object matches this type.
The __private__
and :__reference__
keys are for internal use.
Link to this section Functions
Callback implementation for c:Absinthe.Introspection.TypeKind.kind/0
.