absinthe v1.2.6 Absinthe.Resolution

The primary piece of metadata passed to aid resolution functions, describing the current field’s execution environment.

Summary

Types

t()

Information about the current resolution

Functions

Call a resolution function with its parent, args, and field Info

Types

t()
t :: %Absinthe.Resolution{adapter: Absinthe.Adapter.t, context: map, definition: Blueprint.node_t, parent_type: Absinthe.Type.t, root_value: any, schema: Absinthe.Schema.t, source: any}

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(function, args, info)
call(resolution_function, parent, args, field_info)

Call a resolution function with its parent, args, and field Info

When composing resolution functions, it is important to call this function instead of manually calling inner resolution functions. This is to support the various different forms that the resolution function can take:

DO NOT

def authenticated(fun) do
  fn parent, args, info ->
    case info.context do
      %{current_user: _} ->
        fun.(parent, args, info) # THIS LINE IS WRONG
      _ ->
        {:error, "unauthorized"}
    end
  end
end

DO

def authenticated(fun) do
  fn parent, args, info ->
    case info.context do
      %{current_user: _} ->
        Absinthe.Resolution.call(fun, parent, args, info) # THIS LINE IS CORRECT
      _ ->
        {:error, "unauthorized"}
    end
  end
end