absinthe v1.4.0-rc.3 Absinthe.Resolution.Helpers View Source
Handy functions for returning async or batched resolution functions
It is automatically imported into all modules using Absinthe.Schema.Notation
or (by extension) Absinthe.Schema.
Link to this section Summary
Functions
Execute resolution field asynchronously
Batch the resolution of several functions together
Link to this section Types
Link to this type
dataloader_tuple()
View Source
dataloader_tuple() :: {:middleware, Absinthe.Middleware.Dataloader, term}
Link to this section Functions
Link to this function
async(fun, opts \\ [])
View Source
async((() -> term), Keyword.t) :: {:middleware, Absinthe.Middleware.Async, term}
Execute resolution field asynchronously.
This is a helper function for using the Absinthe.Middleware.Async.
Forbidden in mutation fields. (TODO: actually enforce this)
Link to this function
batch(batch_fun, batch_data, post_batch_fun, opts \\ [])
View Source
batch(Absinthe.Middleware.Batch.batch_fun, term, Absinthe.Middleware.Batch.post_batch_fun, opts :: Keyword.t) :: {:plugin, Absinthe.Middleware.Batch, term}
Batch the resolution of several functions together.
Helper function for creating Absinthe.Middleware.Batch
Example
Raw usage:
object :post do
field :name, :string
field :author, :user do
resolve fn post, _, _ ->
batch({__MODULE__, :users_by_id}, post.author_id, fn batch_results ->
{:ok, Map.get(batch_results, post.author_id)}
end)
end
end
end
def users_by_id(_, user_ids) do
users = Repo.all from u in User, where: u.id in ^user_ids
Map.new(users, fn user -> {user.id, user} end)
end
Link to this function
dataloader(source)
View Source
dataloader(Dataloader.source_name) :: dataloader_tuple
Link to this function
dataloader(source, opts)
View Source
dataloader(Dataloader.source_name, [{:use_parent, true | false}]) :: dataloader_tuple
Link to this function
dataloader(source, key, opts \\ [])
View Source
dataloader(Dataloader.source_name, any, [{:use_parent, true | false}]) :: dataloader_tuple