Graphql-ruby: RuntimeError: No connection implementation to wrap ...

Created on 25 Oct 2018  路  5Comments  路  Source: rmosolgo/graphql-ruby

Graphql version: 1.8.11

I am using graphlient (0.3.3) to write queries in my test. All queries run fine but when I write the query:

response = client.query do
  query do
    postsConnection do
      totalCount
    end
  end
end

I get this:

Failure/Error: result = KudosBackendSchema.execute(query, variables: variables, context: context, operation_name: operation_name)

     RuntimeError:
       No connection implementation to wrap Post::ActiveRecord_Relation (#<Post::ActiveRecord_Relation:0x00007f8ff4421888>)
     # ./app/controllers/graphql_controller.rb:14:in `execute'
     # ./spec/graphql/connections/posts_connection_spec.rb:18:in `block (2 levels) in <top (required)>'
     # ./spec/rails_helper.rb:59:in `block (3 levels) in <top (required)>'
     # ./spec/rails_helper.rb:58:in `block (2 levels) in <top (required)>'

I am assuming it's an issue of graphql and not from the graphlient gem. Any ideas what is causing this?

Most helpful comment

Hmmmm ... maybe for some reason the code to register the wrapper wasn't run, could you try adding this to your schema file? Add this line:

GraphQL::Relay::BaseConnection.register_connection_implementation(ActiveRecord::Relation, GraphQL::Relay::RelationConnection)

All 5 comments

Internally, GraphQL-Ruby tries to match _list objects_ (like Arrays and ActiveRecord::Relations) to _connection implementations_ (which provide cursor pagination etc) based on the object's class. GraphQL-Ruby has a built-in GraphQL::Relay::RelationConnection which is supposed to be matched to ActiveRecord::Relation, but for some reason ... it's not working here!

In fact, the gem couldn't find any connection wrapper for Post::ActiveRecord_Relation. What Rails version are you on? That looks like a generated class, so maybe some Rails version does things a bit differently?

I am on the latest version of rails 5.2.1

Hmmmm ... maybe for some reason the code to register the wrapper wasn't run, could you try adding this to your schema file? Add this line:

GraphQL::Relay::BaseConnection.register_connection_implementation(ActiveRecord::Relation, GraphQL::Relay::RelationConnection)

Yess the test is passing! Any idea why it is not triggered in the test? The query is returning everything just fine in development env.

Glad to hear it! Probably something to do with library load order, since graphql-ruby makes an if defined? check, that check might fail:

https://github.com/rmosolgo/graphql-ruby/blob/24d5c4bcf72f52a69086d63746a121564d44d117/lib/graphql/relay/relation_connection.rb#L179-L181

Was this page helpful?
0 / 5 - 0 ratings

Related issues

theodorton picture theodorton  路  3Comments

amozoss picture amozoss  路  3Comments

dsgoers picture dsgoers  路  3Comments

EAdeveloper picture EAdeveloper  路  3Comments

jturkel picture jturkel  路  3Comments