AbsinthePermission.Middleware (AbsinthePermission v1.0.0)

Copy Markdown View Source

Absinthe middleware that enforces AbsinthePermission rules.

You don't usually call this directly. use AbsinthePermission installs a middleware/3 callback on your schema that wires this in for every field with rules.

How it attaches

For each field, the schema's middleware/3 callback runs at compile time. attach/4 looks up the rules for that field on the schema:

  • If there are pre-op rules (those with on_deny: :error), this module is prepended to the field's middleware list.
  • If there are post-op rules (those with on_deny: :null or :filter), this module is appended.
  • Fields with no rules are untouched.

Telemetry

Every decision emits one of:

  • [:absinthe_permission, :decision, :allow]
  • [:absinthe_permission, :decision, :deny]
  • [:absinthe_permission, :decision, :nullify]

with measurements %{duration: native_time} and metadata %{schema: ..., type: ..., field: ..., decision: %Decision{}}.

Loader events are emitted by AbsinthePermission.Evaluator — see its docs.

Summary

Functions

Wraps a field's middleware list with pre-/post-op checks based on the rules registered on the schema. Designed to be called from a schema's middleware/3 callback.

Functions

attach(middleware, field, object, schema)

@spec attach([Absinthe.Middleware.spec()], any(), any(), module()) :: [
  Absinthe.Middleware.spec()
]

Wraps a field's middleware list with pre-/post-op checks based on the rules registered on the schema. Designed to be called from a schema's middleware/3 callback.