Sucrose v0.1.0 Sucrose.Middleware.SimpleOrPolicy

This is a simple OR policy handler that takes a very simple approach to absinthe resolution handling The basis for all of the handlers is to have a common response type:

true, false, :ok, :error, {:ok, _}, {:error, message}

This will loop through until we have at least one claim that matches.

Think of this one as an or logic.

For posts a context with the claims of:

[:author, :owner, :reader]

For a mutation of deleting you might be ok with an :author or an :owner coming through and being able to delete a post.

This Policy will stop the first chance it gets with a true condition.

Another helper aspect of this will allow for a pattern of :error_out which means that if we ever reach this, we stop the or logic and hard escape out.

However for this to work you MUST put this as your first because otherwise with the or logic it will exit the first :ok or true it gets.

Link to this section Summary

Functions

This is the main middleware callback.

This is the default error handler to put when we want to deny something.

Link to this section Functions

Link to this function

call(resolution, arg2)

This is the main middleware callback.

It receives an %Absinthe.Resolution{} struct and it needs to return an %Absinthe.Resolution{} struct. The second argument will be whatever value was passed to the middleware call that setup the middleware.

Callback implementation for Absinthe.Middleware.call/2.

Link to this function

claims_check(check, claims, handler, last \\ :error)

Link to this function

handle_error(check, message \\ "Unauthorized")

This is the default error handler to put when we want to deny something.

Link to this function

simple_resolution(resolution)

simple_resolution(map()) :: %{child: :atom, parent: :atom, resolution: map()}