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?
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:
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: