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

DuplicateNamesError on a field when upgrading to 1.13 #3949

Closed
Tyflomate opened this issue Feb 18, 2022 · 5 comments
Closed

DuplicateNamesError on a field when upgrading to 1.13 #3949

Tyflomate opened this issue Feb 18, 2022 · 5 comments

Comments

@Tyflomate
Copy link

Tyflomate commented Feb 18, 2022

Describe the bug
When upgrading to 1.13.0, I get Found two visible definitions for 'Events__titletransferred.quantity' but it doesn't seem to be right since in older version (1.12.16) I do not get this error. This type is created from Dry::Struct.graphql_type which comes from this class:

class TitleTransferred < MovementEvent
    attribute :label, Types::String
    attribute :quantity, Types::Integer
    attribute :previous_quantity, Types::Integer
    attribute :right_id, Types::Integer
    attribute :nature, Types::String
    attribute :source_title_id, Types::UUID
    attribute :source_title_metadata, Types::TitleMetadata
    attribute :source_bucket_id, Types::Integer
    attribute :source_bucket_metadata, Types::BucketMetadata
    attribute :destination_title_id, Types::UUID
    attribute? :destination_bucket_id, Types::Integer.optional
    attribute? :destination_bucket_metadata, Types::BucketMetadata.optional
    attribute? :context, Types::String.optional
  end

Inherited classes do not implement a quantity attribute so i do not understand this error message (it seems to do this for all my events implementing a quantity attribute). I've seen a similar issue (#3919) but it was with mutation types and i tried running all_types methods to see the arguments of this gql type but i didn't manage to put a pry at the correct location to try this out.
Versions

graphql version: 1.13.0
rails (or other framework): 6.1.4.4

Hope you can help me out! Thank you

@rmosolgo
Copy link
Owner

Hi! sorry for the trouble. This usually happens when the same field is defined more than once.

In 1.12, the second field definition would overwrite the first one. But in 1.13, GraphQL-Ruby supports multiple definitions for the same field, but requires some way to distinguish between them. When it can't tell the two definitions apart, it raises this error.

If that's not enough info to track down the problem, could you please share the source for Dry::Struct.graphql_type? I searched https://github.com/dry-rb/dry-struct but didn't find it.

@Tyflomate
Copy link
Author

Oh my bad sorry, it comes from dry-graphql: https://github.com/ianks/dry-graphql/blob/master/lib/dry/graphql.rb. Well, I can't find a second definition for this field unfortunately so i am indeed unable to track down correctly the source of the problem :/

@rmosolgo
Copy link
Owner

Thanks for sharing that link. I looked through the code, but I couldn't quite make enough sense of it to figure out why it might make a schema that defined the same field twice. I can think of a couple next steps:

  • Create a minimal reproduction of the error, a script that raises the same kind of errors using that gem, and we can investigate from there
  • Or, check in with the maintainer(s) of dry-graphql to see if they might have some insight as to where the same field might be defined more than once

@Tyflomate
Copy link
Author

Thanks for your answer, I'll try to investigate myself into dry-graphql to find out why it creates two same fields.

@rmosolgo
Copy link
Owner

I hope you got to the bottom of it. Let me know if there's anything else to investigate on the GraphQL side!

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