Skip to content

Commit

Permalink
Merge pull request #1015 from binaryseed/import_fields-input-__typename
Browse files Browse the repository at this point in the history
Fix introspection bug with import_fields and input
  • Loading branch information
binaryseed committed Jan 2, 2021
2 parents fcd1ba5 + d437a58 commit 4cb5beb
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/absinthe/phase/schema/field_imports.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ defmodule Absinthe.Phase.Schema.FieldImports do
Schema.InputObjectTypeDefinition,
Schema.InterfaceTypeDefinition
]
@exclude_fields [
:__typename
]
def import_fields(%def_type{} = type, types) when def_type in @can_import do
Enum.reduce(type.imports, type, fn {source, opts}, type ->
source_type = Map.fetch!(types, source)

rejections = Keyword.get(opts, :except, [])
rejections = Keyword.get(opts, :except, []) ++ @exclude_fields

fields = source_type.fields |> Enum.reject(&(&1.identifier in rejections))

Expand Down
45 changes: 45 additions & 0 deletions test/absinthe/introspection_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,51 @@ defmodule Absinthe.IntrospectionTest do
result
)
end

defmodule ImportFieldsIntoInputSchema do
use Absinthe.Schema

query do
field :test, :test_object do
arg :test, :test_input
end
end

object :test_object do
import_fields(:import_object)
end

input_object :test_input do
import_fields(:import_object)
end

object :import_object do
field :id, :id
end
end

test "import_fields won't import __typename" do
{:ok, %{data: data}} =
"""
{
__schema {
types {
name
inputFields {
name
}
}
}
}
"""
|> Absinthe.run(ImportFieldsIntoInputSchema)

type =
get_in(data, ["__schema", "types"])
|> Enum.find(&(&1["name"] == "TestInput"))

assert get_in(type, ["inputFields"]) == [%{"name" => "id"}]
end
end

describe "introspection of an object type" do
Expand Down

0 comments on commit 4cb5beb

Please sign in to comment.