graphql-client icon indicating copy to clipboard operation
graphql-client copied to clipboard

Error loading schema because it has been defined

Open amree opened this issue 4 years ago • 0 comments

Hey guys, I'm getting this error when I was trying to initiate the client:

ArgumentError (Can't define Block to represent type _Block_ because it's already defined)

FYI, I can load and query the data just fine in Insomnia, so, it considers this schema valid. However, it failed with graphql-client.

You can see the schema at https://gist.github.com/amree/b2127482b05b42bc6febf65dd385a478. You can also try out the query at https://thegraph.com/explorer/subgraph/blocklytics/ethereum-blocks

It seems like because of the Block and _Block_ definitions and in graphql-client code, it will end up as the same name:

https://github.com/github/graphql-client/blob/a1c8318c98de3ff9ed6bfd05b31ed70b4ca847dd/lib/graphql/client/schema.rb#L64-L66

From the console:

irb(main):001:0> http = GraphQL::Client::HTTP.new("https://api.thegraph.com/subgraphs/name/blocklytics/ethereum-blocks")
=> #<GraphQL::Client::HTTP:0x00007fbb455cd0c0 @uri=#<URI::HTTPS https://api.thegraph.com/subgraphs/name/blocklytics/ethereum-blocks>>
irb(main):002:0> schema = GraphQL::Client.load_schema(http)
=> #<GraphQL::Schema ...>
irb(main):003:0> client = GraphQL::Client.new(schema: schema, execute: http)
Traceback (most recent call last):
        8: from ./bin/console:58:in `<main>'
        7: from (irb):3
        6: from (irb):3:in `new'
        5: from /Users/amree/.gem/ruby/2.5.6/gems/graphql-client-0.16.0/lib/graphql/client.rb:101:in `initialize'
        4: from /Users/amree/.gem/ruby/2.5.6/gems/graphql-client-0.16.0/lib/graphql/client/schema.rb:74:in `generate'
        3: from /Users/amree/.gem/ruby/2.5.6/gems/graphql-client-0.16.0/lib/graphql/client/schema.rb:74:in `each'
        2: from /Users/amree/.gem/ruby/2.5.6/gems/graphql-client-0.16.0/lib/graphql/client/schema.rb:78:in `block in generate'
        1: from /Users/amree/.gem/ruby/2.5.6/gems/graphql-client-0.16.0/lib/graphql/client/schema.rb:47:in `set_class'
ArgumentError (Can't define Block to represent type _Block_ because it's already defined)
irb(main):004:0>

I'm not sure if this a bug or the schema needs to be updated (it's not mine). Any hints will be highly appreciated 😁

amree avatar Nov 13 '20 02:11 amree