AbsintheAuth v0.2.1 AbsintheAuth.Policy
Helper functions for use in policies.
Usage
defmodule MyPolicy do
use AbsintheAuth.Policy
end
Link to this section Summary
Functions
Allows a request
Fetches an argument from the current resolution
Defers a request for a decision in a subsequent policy. If no decision is made the request will be denied
Denies a request
Returns true if the current request is a mutation”
Link to this section Functions
Link to this function
allow!(resolution)
allow!(resolution :: Absinthe.Resolution.t()) :: Absinthe.Resolution.t()
Allows a request
For example:
def check(resolution, _opts) do
allow!(resolution)
end
Link to this function
arg(resolution, arg)
Fetches an argument from the current resolution.
Say we have a schema as follows:
query do
field :movie, :movie do
arg :id, non_null(:id)
policy MoviePolicy, :view
resolve &MovieResolver.find_movie/2
end
end
In our policy we can fetch the id
used that passed to the request:
defmodule MoviePolicy do
use AbsintheAuth.Policy
def view(resolution, _) do
id = arg(resolution, id)
SomeModule.that_checks_if_we_can_view_this_movie(id)
end
end
Link to this function
defer(resolution)
defer(resolution :: Absinthe.Resolution.t()) :: Absinthe.Resolution.t()
Defers a request for a decision in a subsequent policy. If no decision is made the request will be denied.
For example:
def check(resolution, _opts) do
defer!(resolution)
end
Link to this function
deny!(resolution)
deny!(resolution :: Absinthe.Resolution.t()) :: Absinthe.Resolution.t()
Denies a request
For example:
def check(resolution, _opts) do
deny!(resolution)
end
Link to this function
is_mutation?(resolution)
is_mutation?(resolution :: Absinthe.Resolution.t()) :: boolean()
Returns true if the current request is a mutation”