Graphql-ruby: Undefined method `edge_nodes'

Created on 26 Nov 2016  路  2Comments  路  Source: rmosolgo/graphql-ruby

Hello all!

I'm trying to port my REST api to graphql and everything is going well so far. I have few associated models that can be fetched using graphql.

However, after adding another one (in the same way as the other working ones), graphql-ruby is throwing an exception

NoMethodError - undefined method `edge_nodes' for #<Photo::ActiveRecord_Associations_CollectionProxy:0x007fc4bca360f0>

Here are my files:

lunch_type.rb

LunchType = GraphQL::ObjectType.define do
  name "Lunch"
  field :photos, PhotosField
end

photos_field.rb

PhotosField = GraphQL::Field.define do
  name 'photos'
  type PhotoType.connection_type

  resolve(PhotosResolver.new)
end

photos_resolver.rb

class PhotosResolver
  def call(obj, _args, _ctx)
    obj.photos
  end
end

And running a following query:

query {
  lunches {
    edges {
      node {
        id
        photos {
          edges {
            node {
              id
            }
          }
        }
      }
    }
  }
}

Raises that exception mentioned above. Can anyone point me on what that actually means and how to debug what's happening? Important thing is that i have exact the same relations/connections (1-n) defined in the exact same way and they are working fine.

Thanks in advance!

Most helpful comment

I think you should change from:

 field :photos, PhotosField

to:

 connection :photos, PhotosField

Does that help?

All 2 comments

I think you should change from:

 field :photos, PhotosField

to:

 connection :photos, PhotosField

Does that help?

Yes, totally. I'm not sure why i didn't tried that in first place. Thanks for your support!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dsgoers picture dsgoers  路  3Comments

jesster2k10 picture jesster2k10  路  3Comments

KevinColemanInc picture KevinColemanInc  路  3Comments

crice88 picture crice88  路  3Comments

jtippett picture jtippett  路  3Comments