Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't pass introspection fields or objects to the def middleware callback #893

Merged
merged 1 commit into from
Mar 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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