Skip to content

Commit

Permalink
Improve function to skip authorization for subscriptions modules
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoLeiteSC committed Jun 4, 2021
1 parent 091fc34 commit 8bdf57e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ defmodule Rajska.Schema do
QueryAuthorization
}

@modules_to_skip [Absinthe.Phase.Schema.Introspection]

@spec add_query_authorization(
[Middleware.spec(), ...],
Field.t(),
module()
) :: [Middleware.spec(), ...]
def add_query_authorization(middlewares, %Field{name: query_name}, authorization) do
def add_query_authorization(middlewares, %Field{name: query_name, definition: definition_module}, authorization)
when definition_module not in @modules_to_skip do
middlewares
|> Enum.find(&find_middleware/1)
|> case do
Expand All @@ -31,6 +34,8 @@ defmodule Rajska.Schema do
middlewares
end

def add_query_authorization(middlewares, _field, _authorization), do: middlewares

def find_middleware({{QueryAuthorization, :call}, _config}), do: true
def find_middleware({{Absinthe.Resolution, :call}, _config}), do: true
def find_middleware({_middleware, _config}), do: false
Expand Down

0 comments on commit 8bdf57e

Please sign in to comment.