Skip to content

Commit

Permalink
Add plugin implementation
Browse files Browse the repository at this point in the history
This can be used as an alternative to pipeline modification.
  • Loading branch information
jeroenvisser101 committed Jul 16, 2020
1 parent f0de230 commit a5d8a06
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/middlewares/object_scope_authorization.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,17 @@ defmodule Rajska.ObjectScopeAuthorization do
alias Absinthe.{Blueprint, Phase, Type}
alias Rajska.Introspection
use Absinthe.Phase
@behaviour Absinthe.Plugin

@spec run(Blueprint.t() | Phase.Error.t(), Keyword.t()) :: {:ok, map}
def run(%Blueprint{execution: execution} = bp, _options \\ []) do
{:ok, %{bp | execution: process(execution)}}
end

def pipeline(pipeline, _execution), do: pipeline
def before_resolution(execution), do: execution
def after_resolution(execution), do: process(execution)

defp process(%{validation_errors: [], result: result} = execution), do: %{execution | result: result(result, execution.context)}
defp process(execution), do: execution

Expand All @@ -80,6 +85,9 @@ defmodule Rajska.ObjectScopeAuthorization do
result
end

# No fields because of non_null violation further down the tree
defp result(%{fields: nil} = result, _context), do: result

# Root
defp result(%{fields: fields, emitter: %{schema_node: %{identifier: identifier}}} = result, context)
when identifier in [:query, :mutation, :subscription] do
Expand Down

0 comments on commit a5d8a06

Please sign in to comment.