-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Same Interface Shows Up Multiple Times in "Implements" #3932
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
Conversation
unsure if this is the right way to do it
|
D'oh! Thanks for the fix on this. One thing on my mind is, what about the list of I definitely want to get this fixed, but I'd prefer a solution that builds the schema properly rather than one that cleans up structure issues at the "last minute." I suspect that what we really need is some duplicate checking in this method:
Here's where an interfaces's interfaces are added to the object type: graphql-ruby/lib/graphql/schema/member/has_interfaces.rb Lines 22 to 25 in faeef68
Maybe that line should somehow check whether this type already implemented that interface. Alternatively, here's some code that replaces "temporary" interface implementations with newly-created ones: graphql-ruby/lib/graphql/schema/member/has_interfaces.rb Lines 36 to 49 in faeef68
Sometimes, when a schema is loading, it uses Strings or Anyhow... not sure exactly which approach would work best, but I'd like to get the schema structure "right" on the way in somehow. Would you like to take a crack at it? If not, I can probably take a look soon. |
|
Thanks for the quick and thoughtful response! Agree and I'll look into a righter approach. For any other reckless interfaciers who find this through google, here's a workaround: # BaseObject
def self.interfaces(...)
super.uniq
end
# BaseInterface
definition_methods do
def interfaces(...)
super.uniq
end
end |
63b551d to
0f6aead
Compare
|
Added another commit along the lines of your second suggestion: graphql-ruby/lib/graphql/schema/member/has_interfaces.rb Lines 48 to 53 in 0f6aead
Tests seem to pass, but:
|
|
Looking good so far, thanks again for taking another look at this!
Yeah, I think that's good. The previous code uses names, but I think that's because it's trying to match Strings or LateBoundTypes (which only have names).
Given the options, seems good to me 👍
Good call 🍻 |
|
It looks like the last implementation winning and overwriting existing memberships options is what's causing the test failures. Deduplicating when new interfaces are added means that things like this won't work: graphql-ruby/spec/graphql/schema/dynamic_members_spec.rb Lines 196 to 197 in b957fb5
Seems safest to keep all the type memberships around and just dedupe the returned list of interfaces. |
|
🤦 D'oh, of course it does. I was thinking only of the case where you might have two interface definitions with the same name (but the interfaces are different in Ruby-land), but I forgot about that feature, where you use the same interface but provide different options to the implementation relationship. Thanks for looking into it, but sorry I pointed you in the wrong direction. Thanks again for this fix! I'm going to follow up on one more thing on another branch (#3954) |
|
No problem! Thanks for this amazing library! |
Per #3613 I put interfaces in my interfaces 🎉
But now my types have too many interfaces 🤢
Specifically, if you've got a schema like this:
And you add a type
Thingthat implementsNamedandTimestamped, printing the schema will give you this:I didn't see much in the spec about this but the reference implementation doesn't like it:
https://github.com/graphql/graphql-js/blob/95dac43fd4bff037e06adaa7cfb44f497bca94a7/src/type/validate.ts#L338-L348
It's also not stable - graphql-ruby will add an additional
& Nodeeach time you parse and then print the SDL.First commit: does it just in the printer.
Second commit: tries to do it for the schema/introspection as well. Wasn't 100% sure about where the deduping should happen though (
#implementsvs#interfacesvs#interface_type_membershipsvs#own_interface_type_memberships.)