View Source Absinthe.Middleware.Async (absinthe v1.7.9)

This plugin enables asynchronous execution of a field.

See also Absinthe.Resolution.Helpers.async/1

Example Usage:

Using the Absinthe.Resolution.Helpers.async/1 helper function:

field :time_consuming, :thing do
  resolve fn _, _, _ ->
    async(fn ->
      {:ok, long_time_consuming_function()}
    end)
  end
end

Using the bare plugin API

field :time_consuming, :thing do
  resolve fn _, _, _ ->
    task = Task.async(fn ->
      {:ok, long_time_consuming_function()}
    end)
    {:middleware, Elixir.Absinthe.Middleware.Async, task}
  end
end

This module also serves as an example for how to build middleware that uses the resolution callbacks.

See the source code and associated comments for further details.

Summary

Functions

after_resolution(exec)

Callback implementation for Absinthe.Plugin.after_resolution/1.

async(fun)

@spec async((-> any())) :: Task.t()

See OpentelemetryProcessPropagator.Task.async/1.

before_resolution(exec)

Callback implementation for Absinthe.Plugin.before_resolution/1.

call(res, task)

Callback implementation for Absinthe.Middleware.call/2.

pipeline(pipeline, exec)

Callback implementation for Absinthe.Plugin.pipeline/2.