Skip to content

Commit

Permalink
Prevent key :is_type_of not found error on interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
maennchen committed Nov 26, 2021
1 parent 6889e0b commit cd0905a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/absinthe/type/interface.ex
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ defmodule Absinthe.Type.Interface do
end
else
type_name =
Enum.find(implementors, fn type ->
implementors
|> Enum.filter(&match?(%Type.Object{}, &1))
|> Enum.find(fn type ->
Absinthe.Type.function(type, :is_type_of).(obj)
end)

Expand Down
45 changes: 45 additions & 0 deletions test/absinthe/type/interface_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,49 @@ defmodule Absinthe.Type.InterfaceTest do
test "works even when resolve_type returns nil" do
assert_data(%{"namedThing" => %{}}, run(@graphql, Schema))
end

defmodule NestedInterfacesSchema do
use Absinthe.Schema

interface :root do
field :root, :string
end

interface :intermediate do
field :root, :string
field :intermediate, :string

interface :root
end

# Name starts with Z to order it to the back of the list of types
object :z_child do
field :root, :string
field :intermediate, :string
field :child, :string

interface :root
interface :intermediate

is_type_of fn _entry -> true end
end

query do
field :root, :root do
resolve fn _, _, _ -> {:ok, %{}} end
end
end
end

@graphql """
query GetRoot {
root {
__typename
}
}
"""

test "resolved type of nested interfaces" do
assert_data(%{"root" => %{"__typename" => "ZChild"}}, run(@graphql, NestedInterfacesSchema))
end
end

0 comments on commit cd0905a

Please sign in to comment.