Speakeasy.LoadResourceBy (Speakeasy v0.3.2)

A convienence middleware to LoadResource using a specified key 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, opts)

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(:blog_id, non_null(:string))
    arg(:name, non_null(:string))
    middleware(Speakeasy.Authn)
    middleware(Speakeasy.LoadResourceBy, {:blog_id, &MyApp.Blogs.get_blog/1})
    middleware(Speakeasy.Authz, {MyApp.Posts, :create_post})
    middleware(Speakeasy.Resolve, fn (blog, attrs, _user) -> MyApp.Posts.create_post(blog, attrs) end)

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