Speakeasy.LoadResource (Speakeasy v0.3.2)
Loads a resource into the speakeasy context:
%Absinthe.Resolution{context: %{speakeasy: %Speakeasy.Context{resource: your_resource}}}
See the README for a complete example in a Absinthe Schema.
Link to this section Summary
Functions
Handles loading a resource or resources and storing them in the Speakeasy.Context
for later resolving.
Link to this section Functions
Link to this function
call(res, fun)
Handles loading a resource or resources and storing them in the Speakeasy.Context
for later resolving.
Callback functions must return a type of: any | {:ok, any} | {:error, error} | nil
. It is effectively looking for the return signatures of Phoenix Contexts.
Examples
Loading a resource with a 1-arity function will receive the Absinthe arguments:
object :post_mutations do
@desc "Create post"
field :create_post, type: :post do
arg(:name, non_null(:string))
middleware(Speakeasy.Authn)
middleware(Speakeasy.LoadResource, fn(attrs) -> MyApp.Posts.create_post(attrs) end)
end
end
Loading a resource with a 2-arity function will receive the Absinthe arguments and the SpeakEasy
current user:
object :post_mutations do
@desc "Create post"
field :create_post, type: :post do
arg(:name, non_null(:string))
middleware(Speakeasy.Authn)
middleware(Speakeasy.LoadResource, fn(attrs, user) -> MyApp.Posts.create_post(attrs, user) end)
end
end