batch-loader 1.2.2 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/README.md +3 -3
- data/lib/batch_loader/graphql.rb +28 -12
- data/lib/batch_loader/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7165f52041d179cfe8de386a0d761d35d1cbca2
|
4
|
+
data.tar.gz: 0d4f594bea1a9d78cb3b94f41c90cf14860dedee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 157d5e17609ef8dc6df9ee49755441083d5d49f5b482e14087d8fba3d004ecb2e1a721ae28eb77a5b23be399c99383cf8cc29cdc0e0efe7d88d051bd44c80412
|
7
|
+
data.tar.gz: a2ad4e96c32219022efa84d7d27bfb90244ce8e8c54072370d5e667031bbc2bf37faee159f645d632b72d440b45a6c2e0b5074c216572ff7b3bf9cc334362cc3
|
data/CHANGELOG.md
CHANGED
@@ -8,10 +8,14 @@ one of the following labels: `Added`, `Changed`, `Deprecated`,
|
|
8
8
|
to manage the versions of this gem so
|
9
9
|
that you can set version constraints properly.
|
10
10
|
|
11
|
-
#### [Unreleased](https://github.com/exAspArk/batch-loader/compare/v1.
|
11
|
+
#### [Unreleased](https://github.com/exAspArk/batch-loader/compare/v1.3.0...HEAD)
|
12
12
|
|
13
13
|
* WIP
|
14
14
|
|
15
|
+
#### [v1.3.0](https://github.com/exAspArk/batch-loader/compare/v1.2.2...v1.3.0)
|
16
|
+
|
17
|
+
* `Added`: `BatchLoader::GraphQL` to make it work with `graphql` gem version `>= 1.8.7`. [#30](https://github.com/exAspArk/batch-loader/issues/30)
|
18
|
+
|
15
19
|
#### [v1.2.2](https://github.com/exAspArk/batch-loader/compare/v1.2.1...v1.2.2)
|
16
20
|
|
17
21
|
* `Fixed`: Identify item by `key` object instead of `key` string representation. [#27](https://github.com/exAspArk/batch-loader/pull/27)
|
data/README.md
CHANGED
@@ -258,13 +258,13 @@ query = "
|
|
258
258
|
Schema.execute(query)
|
259
259
|
```
|
260
260
|
|
261
|
-
To avoid this problem, all we have to do is to change the resolver to return `BatchLoader
|
261
|
+
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`):
|
262
262
|
|
263
263
|
```ruby
|
264
264
|
PostType = GraphQL::ObjectType.define do
|
265
265
|
name "Post"
|
266
266
|
field :user, !UserType, resolve: ->(post, args, ctx) do
|
267
|
-
BatchLoader.for(post.user_id).batch do |user_ids, loader|
|
267
|
+
BatchLoader::GraphQL.for(post.user_id).batch do |user_ids, loader|
|
268
268
|
User.where(id: user_ids).each { |user| loader.call(user.id, user) }
|
269
269
|
end
|
270
270
|
end
|
@@ -314,7 +314,7 @@ def lazy_association(post)
|
|
314
314
|
|
315
315
|
BatchLoader.for(id).batch(key: key) do |ids, loader, args|
|
316
316
|
model = Object.const_get(args[:key])
|
317
|
-
model.where(id: ids).each { |record|
|
317
|
+
model.where(id: ids).each { |record| loader.call(record.id, record) }
|
318
318
|
end
|
319
319
|
end
|
320
320
|
post1 = Post.save(association_id: 1, association_type: 'Tag')
|
data/lib/batch_loader/graphql.rb
CHANGED
@@ -2,18 +2,9 @@
|
|
2
2
|
|
3
3
|
class BatchLoader
|
4
4
|
class GraphQL
|
5
|
-
class Wrapper
|
6
|
-
def initialize(batch_loader)
|
7
|
-
@batch_loader = batch_loader
|
8
|
-
end
|
9
|
-
|
10
|
-
def sync
|
11
|
-
@batch_loader.__sync
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
5
|
def self.use(schema_definition)
|
16
|
-
schema_definition.lazy_resolve(BatchLoader::GraphQL
|
6
|
+
schema_definition.lazy_resolve(BatchLoader::GraphQL, :sync)
|
7
|
+
# for graphql gem versions <= 1.8.6 which work with BatchLoader instead of BatchLoader::GraphQL
|
17
8
|
schema_definition.instrument(:field, self)
|
18
9
|
end
|
19
10
|
|
@@ -21,10 +12,35 @@ class BatchLoader
|
|
21
12
|
old_resolve_proc = field.resolve_proc
|
22
13
|
new_resolve_proc = ->(object, arguments, context) do
|
23
14
|
result = old_resolve_proc.call(object, arguments, context)
|
24
|
-
result.respond_to?(:__sync) ? BatchLoader::GraphQL
|
15
|
+
result.respond_to?(:__sync) ? BatchLoader::GraphQL.wrap(result) : result
|
25
16
|
end
|
26
17
|
|
27
18
|
field.redefine { resolve(new_resolve_proc) }
|
28
19
|
end
|
20
|
+
|
21
|
+
def self.wrap(batch_loader)
|
22
|
+
BatchLoader::GraphQL.new.tap do |graphql|
|
23
|
+
graphql.batch_loader = batch_loader
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.for(item)
|
28
|
+
new(item)
|
29
|
+
end
|
30
|
+
|
31
|
+
attr_writer :batch_loader
|
32
|
+
|
33
|
+
def initialize(item = nil)
|
34
|
+
@batch_loader = BatchLoader.for(item)
|
35
|
+
end
|
36
|
+
|
37
|
+
def batch(*args, &block)
|
38
|
+
@batch_loader.batch(*args, &block)
|
39
|
+
self
|
40
|
+
end
|
41
|
+
|
42
|
+
def sync
|
43
|
+
@batch_loader.__sync
|
44
|
+
end
|
29
45
|
end
|
30
46
|
end
|
data/lib/batch_loader/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: batch-loader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- exAspArk
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|