Closed im-not-a-robot closed 5 years ago
Hi @im-not-a-robot!
Did you add use BatchLoader::GraphQL
to your schema?
It should work without scope: false
and any manual wrapping https://github.com/exAspArk/batch-loader/issues/22#issuecomment-443329419. Here is the test from the current master
, which uses version 1.8.11 in the build:
Yes im already add use BatchLoader::GraphQL
to my schema.
I dont know why when im using make new rails project with new ruby version (2.4.5) and new graphql version (1.8.11), batch loader not work without scope: false
or manual wrapping.
May if you want to see the issue, i can send you the project.
@im-not-a-robot yes, please 🙏 If you can send me the project (e.g. a github repo), that'll save me some time.
Hi, you can get it here : https://github.com/im-not-a-robot/example-ruby-rails-graphql-batch-loader
Hello,
Currently having the same problem above and the scope: false
fixed my issue as well.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Hello @exAspArk Have you try that project?
Looking into it now
@im-not-a-robot unfortunately, I couldn't run your rails example app. Something is wrong with a DB: partially pg, partially sqlite, no migrations, no seed data, etc.
I created a new very basic Rails app which should be relatively simple to run https://github.com/exAspArk/batch-loader-graphql. I use graphql
ruby gem version 1.8.13
with the latest batch-loader
version 1.2.2
, and I can't reproduce it:
Please let me know if you can reproduce it with that rails app. Maybe the latest graphql
ruby gem versions fixed compatibility again.
@im-not-a-robot unfortunately, I couldn't run your rails example app. Something is wrong with a DB: partially pg, partially sqlite, no migrations, no seed data, etc.
I created a new very basic Rails app which should be relatively simple to run https://github.com/exAspArk/batch-loader-graphql. I use
graphql
ruby gem version1.8.13
with the latestbatch-loader
version1.2.2
, and I can't reproduce it:Please let me know if you can reproduce it with that rails app. Maybe the latest
graphql
ruby gem versions fixed compatibility again.
@exAspArk Sorry for the problem. I'm already update the project, please check it again. Thank you. Note:
@im-not-a-robot awesome, thank you!
Could you please try these changes:
# Gemfile
gem 'batch-loader', github: 'exAspArk/batch-loader', branch: 'graphql'
You'd need to replace BatchLoader.for
with BatchLoader::GraphQL.for
to make it actually batch requests with the latest graphql
versions. For example:
class PostType < GraphQL::Schema::Object
field :user, UserType, null: false
def user
BatchLoader::GraphQL.for(object.user_id).batch do |user_ids, loader|
User.where(id: user_ids).each { |user| loader.call(user.id, user) }
end
end
end
I will write more details on the issue later.
@im-not-a-robot awesome, thank you!
Could you please try these changes https://github.com/exAspArk/batch-loader/compare/graphql?expand=1:
# Gemfile gem 'batch-loader', github: 'exAspArk/batch-loader', branch: 'graphql'
You'd need to replace
BatchLoader.for
withBatchLoader::GraphQL.for
to make it actually batch requests with the latestgraphql
versions. For example:class PostType < GraphQL::Schema::Object field :user, UserType, null: false def user BatchLoader::GraphQL.for(object.user_id).batch do |user_ids, loader| User.where(id: user_ids).each { |user| loader.call(user.id, user) } end end end
I will write more details on the issue later.
Yeah its works well. Thank you !
@im-not-a-robot perfect, thank you!
I wrote an explanation about the root cause in https://github.com/exAspArk/batch-loader/pull/32. Will try to ship it tomorrow.
Released these changes in v1.3.0
:
TL;DR
- If you use
graphql
gem version 1.8.6 or lower, you can continue usingBatchLoader
.- If you use
graphql
gem version 1.8.7 or greater, you need to replaceBatchLoader.for
withBatchLoader::GraphQL.for
to make it work within your GraphQL resolvers (methods).
My code for batch loader :
Result :
Here's my gemfile :
Im already use your quick fix on this comment https://github.com/exAspArk/batch-loader/issues/22#issuecomment-413341798 It can solved this problem.
The other solution : https://github.com/rmosolgo/graphql-ruby/issues/1778#issuecomment-429496117 But it must make scope attribute to false
Is there best practice to solve this problem ? Thank you