absinthe v1.3.2 Absinthe.Resolution

The primary struct of resolution.

In many ways like the %Conn{} from Plug, the %Absinthe.Resolution{} is the piece of information that passed along from middleware to middleware as part of resolution.

Summary

Types

t()

Information about the current resolution

Functions

Get the child fields under the current field

Get the child fields under the current field

Handy function for applying user function result tuples to a resolution struct

Types

field_state()
field_state() :: :unresolved | :resolved | :suspended
t()
t() :: %Absinthe.Resolution{acc: %{optional(any) => any}, adapter: Absinthe.Adapter.t, arguments: %{optional(atom) => any}, context: map, definition: Blueprint.node_t, errors: [term], extensions: %{optional(any) => any}, fields_cache: term, fragments: [Blueprint.Document.Fragment.Named.t], middleware: term, parent_type: Type.t, path: term, private: term, root_value: any, schema: Schema.t, source: any, state: field_state, value: term}

Information about the current resolution.

Contents

  • :adapter - The adapter used for any name conversions.
  • :definition - The Blueprint definition for this field.
  • :context - The context passed to Absinthe.run.
  • :root_value - The root value passed to Absinthe.run, if any.
  • :parent_type - The parent type for the field.
  • :schema - The current schema.
  • :source - The resolved parent object; source of this field.

To access the schema type for this field, see the definition.schema_node.

Functions

call(res, resolution_function)
call(function, args, info)
call(resolution_function, parent, args, field_info)

TODO: Deprecate

path_string(resolution)
project(info)

Get the child fields under the current field.

See project/2 for details.

project(info, type)

Get the child fields under the current field.

Example

Given a document like:

{ user { id name }}
field :user, :user do
  resolve fn _, info ->
    child_fields = Absinthe.Resolution.project(info) |> Enum.map(&(&1.name))
    # ...
  end
end

child_fields will be ["id", "name"].

It correctly handles fragments, so for example if you had the document:

{
  user {
    ... on User {
      id
    }
    ... on Named {
      name
    }
  }
}

you would still get a nice and simple child_fields that was ["id", "name"].

put_result(res, result)

Handy function for applying user function result tuples to a resolution struct

User facing functions generally return one of several tuples like {:ok, val} or {:error, reason}. This function handles applying those various tuples to the resolution struct.

The resolution state is updated depending on the tuple returned. :ok and :error tuples set the state to :resolved, whereas middleware tuples set it to :unresolved.

This is useful for middleware that wants to handle user facing functions, but does not want to duplicate this logic.

resolver_spec(fun)
result_error(value, field, source, guess)