absinthe v1.4.0-beta.1 Absinthe.Type.Object View Source

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

Types

t()

A defined object type

Functions

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

Link to this section Types

Link to this type t() View Source
t() :: %Absinthe.Type.Object{__private__: Keyword.t, __reference__: Absinthe.Type.Reference.t, description: binary, field_imports: term, fields: map, identifier: atom, interfaces: [Absinthe.Type.Interface.t], is_type_of: (any -> boolean), 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 TitleCased binary. Set automatically.
  • :description - A nice description for introspection.
  • :fields - A map of Absinthe.Type.Field structs. Usually built via Absinthe.Schema.Notation.field/1.
  • :interfaces - A list of interfaces that this type guarantees to implement. See Absinthe.Type.Interface.
  • :is_type_of - A function used to identify whether a resolved object belongs to this defined type. For use with :interfaces entry and Absinthe.Type.Interface.

The __private__ and :__reference__ keys are for internal use.

Link to this section Functions

Link to this function import_fields(schema, arg, fields) View Source

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