Graphql-ruby: undefined method `map' for #<GraphQL::Relay::ArrayConnection>

Created on 7 Nov 2019  路  4Comments  路  Source: rmosolgo/graphql-ruby

This error occurs when using a 1.8+ version of the gem and DSL style and when you have defined graphql types in your schema that end with the word Connection.

Any types ending with the word Connection automatically get graphql-ruby's connection handling applied to them, which results in the error listed in the title if the resolvers on the fields in question don't return an array or an ActiveRecord::Relation.

In short you get graphql-ruby's connection handling on types for which you may not expect that to happen.

This is particularly surprising when converting from old style DSL (pre.1.8+) where this automatic Connection handling behavior does not exist.

While this is documented here and here (see the docs for a workaround), I would recommend keeping this issue open for the benefit of anyone else who might encounter this error.

Users who are not interested in graphql-ruby's built in connection support might skip over these sections of the documentation and might have difficulties figuring out the cause of the error.

Most helpful comment

Spend a half the day to figure out what's wrong, but after posting a comment (as usual) I've seen extra [] in a field definition.

All 4 comments

Can you share any details about the _actual issue_ you ran into here? did you have a type that got connection handling which _shouldn't have_?

Hello Robert, that was exactly the problem. I updated the description to shorten it and make it a bit more clear. The error currently doesn't even report the type that caused the problem.

Getting the same error. Don't understand what's wrong

 field :real_estates, [Types::RealEstateType.connection_type], null: false
    def real_estates
      RealEstate.all
    end

image

Spend a half the day to figure out what's wrong, but after posting a comment (as usual) I've seen extra [] in a field definition.

Was this page helpful?
0 / 5 - 0 ratings