Skip to content

Commit

Permalink
Merge pull request #893 from absinthe-graphql/no-introspection-middle…
Browse files Browse the repository at this point in the history
…ware-callback

don't pass introspection fields or objects to the def middleware callback
  • Loading branch information
benwilson512 authored Mar 29, 2020
2 parents 4e08399 + 4a73db7 commit 7821d27
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/absinthe/blueprint/schema/object_type_definition.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ defmodule Absinthe.Blueprint.Schema.ObjectTypeDefinition do
fields: build_fields(type_def, schema),
interfaces: type_def.interfaces,
definition: type_def.module,
is_type_of: type_def.is_type_of
is_type_of: type_def.is_type_of,
__private__: type_def.__private__
}
end

Expand Down
19 changes: 15 additions & 4 deletions lib/absinthe/middleware.ex
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,21 @@ defmodule Absinthe.Middleware do

@doc false
def expand(schema, middleware, field, object) do
middleware
|> Enum.flat_map(&get_functions/1)
|> Absinthe.Schema.Notation.__ensure_middleware__(field, object)
|> schema.middleware(field, object)
expanded =
middleware
|> Enum.flat_map(&get_functions/1)
|> Absinthe.Schema.Notation.__ensure_middleware__(field, object)

case middleware do
[{:ref, Absinthe.Phase.Schema.Introspection, _}] ->
expanded

[{:ref, Absinthe.Type.BuiltIns.Introspection, _}] ->
expanded

_ ->
schema.middleware(expanded, field, object)
end
end

defp get_functions({:ref, module, identifier}) do
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Absinthe.Mixfile do
use Mix.Project

@version "1.5.0-rc.4"
@version "1.5.0-rc.5"

def project do
[
Expand Down
15 changes: 15 additions & 0 deletions test/absinthe/integration/execution/introspection/full_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,19 @@ defmodule Elixir.Absinthe.Integration.Execution.Introspection.FullTest do
{:ok, %{data: %{"__schema" => schema}}} = result
assert !is_nil(schema)
end

defmodule MiddlewareSchema do
use Absinthe.Schema

query do
end

def middleware(_, _, _) do
raise "this should not be called when introspecting"
end
end

test "middleware callback does not apply to introspection fields" do
assert Absinthe.run(@query, MiddlewareSchema, [])
end
end

0 comments on commit 7821d27

Please sign in to comment.