# `Permit.Absinthe.Middleware`
[🔗](https://github.com/curiosum-dev/permit_absinthe/blob/v0.3.0/lib/permit_absinthe/middleware.ex#L1)

Middleware for loading and authorizing resources in Absinthe. Uses the raw
resolver function defined in `Permit.Absinthe.Resolvers.LoadAndAuthorize` to
put the resolution outcome in `:loaded_resource` or `:loaded_resources`
(depending on whether it's an index-like or a single-item action).

Useful in mutations where it's not enough to just load a resource, or whenever
you otherwise need to process it after loading.

## Usage, mechanism and configuration

See `Permit.Absinthe.Resolvers.LoadAndAuthorize` for details on resolution of
authorized records in Permit.Absinthe. The middleware delegates

### Example

```elixir
mutation do
  @desc "Update an article"
  field :update_article, :article do
    permit action: :update

    arg(:id, non_null(:id))
    arg(:name, non_null(:string))
    arg(:content, non_null(:string))

    middleware Permit.Absinthe.Middleware

    resolve(fn _, %{name: name, content: content}, %{context: context} ->
      case Blog.Content.update_article(context.loaded_resource, %{name: name, content: content}) do
        {:ok, article} ->
          {:ok, article}

        {:error, changeset} ->
          {:error, "Could not update article"}
      end
    end)
  end
end
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
