From 8bdf57efdb537c1d3bbc7cf55c351b27182dbdaa Mon Sep 17 00:00:00 2001 From: Leonardo Leite Date: Fri, 4 Jun 2021 20:44:03 -0300 Subject: [PATCH] Improve function to skip authorization for subscriptions modules --- lib/schema.ex | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/schema.ex b/lib/schema.ex index 560609a..a5f7ff3 100644 --- a/lib/schema.ex +++ b/lib/schema.ex @@ -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 @@ -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