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

Prevent key :is_type_of not found error on interfaces #1078

Merged

Conversation

maennchen
Copy link
Contributor

@maennchen maennchen commented Jun 2, 2021

Fix for #1077

Based on #1079, merge that one first.

@maennchen maennchen force-pushed the interface_resolve_type_only_object branch 2 times, most recently from 1302be1 to 3d58558 Compare June 2, 2021 11:27
@benwilson512
Copy link
Contributor

Can you include a test case that would fail on master?

@maennchen
Copy link
Contributor Author

@benwilson512 Where was the current functionality of the is_type_of tested?

@benwilson512
Copy link
Contributor

test/absinthe/type/interface_test.exs mostly

@maennchen maennchen force-pushed the interface_resolve_type_only_object branch from 3d58558 to fc71ac0 Compare June 2, 2021 11:45
@@ -102,7 +102,9 @@ defmodule Absinthe.Type.Interface do
end
else
type_name =
Enum.find(implementors, fn type ->
implementors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's actually this list which is wrong. The implementors list should be only concrete implementors. This change should occur in lib/absinthe/blueprint/schema/interface_type_definition.ex find_implementors/1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way the filtering is accomplished at schema building time instead of every time the interface is evaluated at runtime.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm running out of time now, I'll nave a look later 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benwilson512 If I change it in finde_implementors, I break those two tests:

  1) test interfaces are propagated across type imports (Absinthe.Schema.Rule.ObjectMustImplementInterfacesTest)
     test/absinthe/schema/rule/object_must_implement_interfaces_test.exs:88
     Assertion with == failed
     code:  assert %{named: [:cat, :dog, :user], favorite_foods: [:cat, :dog, :user], parented: [:named]} == Schema.__absinthe_interface_implementors__()
     left:  %{favorite_foods: [:cat, :dog, :user], named: [:cat, :dog, :user], parented: [:named]}
     right: %{favorite_foods: [:cat, :dog, :user], named: [:cat, :dog, :user], parented: []}
     stacktrace:
       test/absinthe/schema/rule/object_must_implement_interfaces_test.exs:89: (test)

.

  2) test interfaces are set from sdl (Absinthe.Schema.Rule.ObjectMustImplementInterfacesTest)
     test/absinthe/schema/rule/object_must_implement_interfaces_test.exs:122
     Assertion with == failed
     code:  assert %{image: [], node: [:image, :resource], resource: [:image]} == InterfaceImplementsInterfaces.__absinthe_interface_implementors__()
     left:  %{image: [], node: [:image, :resource], resource: [:image]}
     right: %{image: [], node: [], resource: []}
     stacktrace:
       test/absinthe/schema/rule/object_must_implement_interfaces_test.exs:123: (test)

Do we consider those tests correct or wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benwilson512 In which direction should I continue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tlvenn Now I finally get it. 😄

I'll try that way then

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tlvenn

https://github.com/absinthe-graphql/absinthe/runs/4335029279?check_suite_focus=true

  1) test interfaces are set from sdl (Absinthe.Schema.Rule.ObjectMustImplementInterfacesTest)
Error:      test/absinthe/schema/rule/object_must_implement_interfaces_test.exs:132
     Assertion with == failed
     code:  assert %{image: [], node: [:image, :resource], resource: [:image]} == InterfaceImplementsInterfaces.__absinthe_interface_implementors__()
     left:  %{image: [], node: [:image, :resource], resource: [:image]}
     right: %{image: [], node: [], resource: []}
     stacktrace:
       test/absinthe/schema/rule/object_must_implement_interfaces_test.exs:133: (test)

.

  2) test interfaces are propagated across type imports (Absinthe.Schema.Rule.ObjectMustImplementInterfacesTest)
Error:      test/absinthe/schema/rule/object_must_implement_interfaces_test.exs:98
     Assertion with == failed
     code:  assert %{named: [:cat, :dog, :user], favorite_foods: [:cat, :dog, :user], parented: [:cat, :dog, :named, :user]} == Schema.__absinthe_interface_implementors__()
     left:  %{favorite_foods: [:cat, :dog, :user], named: [:cat, :dog, :user], parented: [:cat, :dog, :named, :user]}
     right: %{
              favorite_foods: [:cat, :dog, :user],
              named: [:cat, :dog, :user],
              parented: [:cat, :dog, :user]
            }
     stacktrace:
       test/absinthe/schema/rule/object_must_implement_interfaces_test.exs:99: (test)

You seem to know that code better. Should I just give you push access to my fork?

Copy link
Member

@tlvenn tlvenn Nov 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha great, thanks for this, I wanted to believe it would work but kinda suspected this could happen. Those 2 issues have been introduced by the original PR that added support for interface implementing interfaces because until now find_implementors/1 was incorrectly returning interfaces instead of just concrete types.

Given that:

  • This test suite is purposely for testing objects that use interfaces.
  • We have other tests against interfaces implementing interfaces in test/absinthe/schema/rule/object_interfaces_must_be_valid_test.exs.
  • Transitively implemented interfaces must also be defined on implementing types.

We should simply get rid of interfaces implementing interfaces in those 2 tests and fix the assertions, we are mixing too many concerns otherwise and the purpose of those tests is lost.

We probably could / should introduce a specific test to assert that find_implementors/1 is only returning concrete types in another place. At the same time, the test you added indirectly address this so probably not so needed.

I am totally happy to take it from there if you want, totally up to you and in any case, thanks again for your time and effort on this. Have a great WE !

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maennchen can you please re send the invitation to collab on your fork, i did not see it initially and it has expired now, thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tlvenn I sent it again :)

@maennchen maennchen force-pushed the interface_resolve_type_only_object branch from fc71ac0 to 360a517 Compare June 2, 2021 11:55
@maennchen
Copy link
Contributor Author

@benwilson512 I added a test.

@maennchen
Copy link
Contributor Author

@benwilson512 Ping :)

@maennchen
Copy link
Contributor Author

@benwilson512 Iw ould really like to finish this PR. Can you give me some guidance on what to do to get it over the line?

@arturs678
Copy link

Any updates on this ?

@maennchen maennchen force-pushed the interface_resolve_type_only_object branch 2 times, most recently from 0d55998 to cd0905a Compare November 26, 2021 14:16
@tlvenn tlvenn merged commit 1ad9f67 into absinthe-graphql:master Dec 9, 2021
@maennchen maennchen deleted the interface_resolve_type_only_object branch December 9, 2021 12:13
@maennchen
Copy link
Contributor Author

@tlvenn Thanks :)

@maennchen maennchen restored the interface_resolve_type_only_object branch December 9, 2021 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants