README.md in batch-loader-1.2.2 vs README.md in batch-loader-1.3.0
- old
+ new
@@ -256,17 +256,17 @@
}
"
Schema.execute(query)
```
-To avoid this problem, all we have to do is to change the resolver to return `BatchLoader`:
+To avoid this problem, all we have to do is to change the resolver to return `BatchLoader::GraphQL` ([#32](https://github.com/exAspArk/batch-loader/pull/32) explains why not just `BatchLoader`):
```ruby
PostType = GraphQL::ObjectType.define do
name "Post"
field :user, !UserType, resolve: ->(post, args, ctx) do
- BatchLoader.for(post.user_id).batch do |user_ids, loader|
+ BatchLoader::GraphQL.for(post.user_id).batch do |user_ids, loader|
User.where(id: user_ids).each { |user| loader.call(user.id, user) }
end
end
end
```
@@ -312,10 +312,10 @@
id = post.association_id
key = post.association_type
BatchLoader.for(id).batch(key: key) do |ids, loader, args|
model = Object.const_get(args[:key])
- model.where(id: ids).each { |record| record.call(record.id, record) }
+ model.where(id: ids).each { |record| loader.call(record.id, record) }
end
end
post1 = Post.save(association_id: 1, association_type: 'Tag')
post2 = Post.save(association_id: 1, association_type: 'Category')