Speakeasy v0.3.1 Speakeasy.LoadResourceByID

A convienence middleware to LoadResource using the :id in the Absinthe arguments.

See the README for a complete example in a Absinthe Schema.

Link to this section Summary

Functions

This calls LoadResource under the hood and extracts the :id out of the arguments map

Link to this section Functions

Link to this function call(resolution, fun)

This calls LoadResource under the hood and extracts the :id out of the arguments map.

Examples

object :post_mutations do
  @desc "Create post"
  field :create_post, type: :post do
    arg(:name, non_null(:string))
    middleware(Speakeasy.Authn)
    middleware(Speakeasy.LoadResourceByID, &MyApp.Posts.get_post/1)

    # This is a shorthand of:
    # middleware(Speakeasy.LoadResource, fn(attrs) -> MyApp.Post.get_post(attrs[:id]))
  end
end