Graphql-ruby: Array connection type is used for AR relations in Rails 3.2

Created on 11 Oct 2016  路  2Comments  路  Source: rmosolgo/graphql-ruby

Given a model with a connection on a has_many association, for instance:

class Worker < ActiveRecord::Base
  has_many :worked_hours, dependent: :destroy
end

WorkerType = GraphQL::ObjectType.define do
  name "Worker"
  field :id, !types.Int, "The id of this worker"
  connection :entries, EntryType.connection_type, "Worked hours", property: :worked_hours
end

EntryType = GraphQL::ObjectType.define do
  name "Entry"
  field :id, !types.Int, "The id of this entry"
  field :record, !types.String, "The record of this entry"
end

When running a query on the connection, the ArrayConnection subclass is used, instead of the RelationConnection. This causes any limits to be issued in memory instead of in the SQL query.

This seems to be happening because the resolver for the Connection subtype relies on the property's class, and Rails 3.2 reports a has_many association to be of class Array, whereas Rails 4+ returns AR::Relation.

Worker.first.worked_hours.class
=> Array

Most helpful comment

:metal: fixed by #343

All 2 comments

Thanks for sharing the details on this! I'll take a look at that connection-matching issue soon.

:metal: fixed by #343

Was this page helpful?
0 / 5 - 0 ratings

Related issues

crice88 picture crice88  路  3Comments

amozoss picture amozoss  路  3Comments

rmosolgo picture rmosolgo  路  4Comments

gastonmorixe picture gastonmorixe  路  3Comments

KevinColemanInc picture KevinColemanInc  路  3Comments