absinthe v1.4.1 Absinthe.Middleware.Async View Source

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.

Link to this section Summary

Functions

callback to do something with the resolution accumulator after resolution

callback to setup the resolution accumulator prior to resolution

This is the main middleware callback

callback used to specify additional phases to run

Link to this section Functions

callback to do something with the resolution accumulator after resolution.

NOTE: This function is given the full accumulator. Namespacing is suggested to avoid conflicts.

Callback implementation for Absinthe.Plugin.after_resolution/1.

callback to setup the resolution accumulator prior to resolution.

NOTE: This function is given the full accumulator. Namespacing is suggested to avoid conflicts.

Callback implementation for Absinthe.Plugin.before_resolution/1.

This is the main middleware callback.

It receives an %Absinthe.Resolution{} struct and it needs to return an %Absinthe.Resolution{} struct. The second argument will be whatever value was passed to the plug call that setup the middleware.

Callback implementation for Absinthe.Middleware.call/2.

Link to this function pipeline(pipeline, exec) View Source

callback used to specify additional phases to run.

Plugins may require additional resolution phases to be run. This function should use values set in the resolution accumulator to determine whether or not additional phases are required.

NOTE: This function is given the whole pipeline to be inserted after the current phase completes.

Callback implementation for Absinthe.Plugin.pipeline/2.