absinthe v1.4.0-beta.1 Absinthe.Resolution View Source

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.

Link to this section 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

Link to this section Types

Link to this type field_state() View Source
field_state() :: :unresolved | :resolved | :suspended
Link to this type t() View Source
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.

Link to this section Functions

Link to this function call(res, resolution_function) View Source
Link to this function call(function, args, info) View Source
Link to this function call(resolution_function, parent, args, field_info) View Source

TODO: Deprecate

Get the child fields under the current field.

See project/2 for details.

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"].

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.

Link to this function result_error(value, field, source, guess) View Source