graphql-ruby
graphql-ruby copied to clipboard
DuplicateTypeNamesError when using Relay's scaffold code Types::NodeType
Describe the bug
The code generated by rails generate graphql:install doesn't seem to work.
# /app/graphql/types/node_type.rb
module Types
module NodeType
include Types::BaseInterface
# Add the `id` field
include GraphQL::Types::Relay::NodeBehaviors
end
end
# /app/graphql/types/user_type.rb
class Types::UserType < Types::BaseObject
implements Types::NodeType
...
end
Results in
GraphQL::Schema::DuplicateTypeNamesError: Multiple definitions for `Node`. Previously found GraphQL::Types::Relay::Node (Module), then found Types::NodeType (Module) at Query.user.implements
Versions
graphql version: 1.12.13
rails (or other framework): 6.1.4
Ahh -- thanks for opening this. I see that the Query.id field uses GraphQL:Types::Relay::Node. It needs some way to accept a return type in the configuration. I'll see what I can find!
Hey, any idea what the workaround for this could be? Just using GraphQL::Types::Relay::Node directly?
This seemed to do the trick for me.
module HasNodesFieldDecorator
def field_options
puts 'I was called'
super.merge(type: [Types::NodeType, null: true])
end
end
module HasNodeFieldDecorator
def field_options
puts 'I was called too'
super.merge(type: Types::NodeType)
end
end
GraphQL::Types::Relay::HasNodeField.singleton_class.prepend(HasNodeFieldDecorator)
GraphQL::Types::Relay::HasNodesField.singleton_class.prepend(HasNodesFieldDecorator)