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

Allow interface implementations to be defined in the implementing type #3128

Closed
nirvdrum opened this issue Sep 3, 2020 · 3 comments
Closed

Comments

@nirvdrum
Copy link
Contributor

nirvdrum commented Sep 3, 2020

Is your feature request related to a problem? Please describe.

I'm building up a tree of heterogeneous data. In order to do so, I have a Types::IntegrationNode module that each of the node types implement. E.g.:

class Types::AwsIntegrationType < Types::BaseObject
  implements GraphQL::Types::Relay::Node
  implements Types::IntegrationNode
  ...
end

The problem is I can't define a method for any of the implemented fields from the implementing type. E.g., if Types::IntegrationNode declares field :name, String, null: false, I can't define Types::AwsIntegrationType#name. Instead, I see an error like:

Failed to implement IntegrationNode.name, tried:
        - `Types::IntegrationServiceTreeType#name`, which did not exist
        - `AwsIntegration#name`, which did not exist
        - Looking up hash key `:name` or `"name"` on `#<AwsIntegration:0x00007f1438b370b0>`, but it wasn't a Hash

        To implement this field, define one of the methods above (and check for typos)

This appears to be inconsistent with how fields declared directly in the type are handled, where I can define a method with the same name and have that used as the implementation.

Describe the solution you'd like

I'd like to be able to define a method corresponding to a field from an implemented interface and have that method invoked as if the field were defined directly in the type.

Describe alternatives you've considered

The error message clearly lists where I can define the method. Adding it to the interface isn't appropriate since I need it overridden in each concrete type. That leaves defining the methods on AwsIntegration, which works.

@rmosolgo
Copy link
Owner

rmosolgo commented Sep 3, 2020

Thanks for the detailed report. It's supposed to work the way you describe, where def name in the object type takes precedence over any method defined in an interface module!

@rmosolgo
Copy link
Owner

rmosolgo commented Sep 3, 2020

I tried to make a simple reproduction of this issue in eafe432, but for me, it worked fine. Could you share an example query that gives this issue? Maybe there's a certain runtime scenario that surfaces the bug.

@rmosolgo
Copy link
Owner

rmosolgo commented Nov 2, 2021

I'd be happy to look into this further if you can provide any more details!

@rmosolgo rmosolgo closed this as completed Nov 2, 2021
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

No branches or pull requests

2 participants