graphql-batch 0.3.5 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/examples/record_loader.rb +1 -4
- data/graphql-batch.gemspec +3 -1
- data/lib/graphql/batch.rb +4 -4
- data/lib/graphql/batch/execution_strategy.rb +1 -1
- data/lib/graphql/batch/executor.rb +21 -24
- data/lib/graphql/batch/loader.rb +25 -16
- data/lib/graphql/batch/mutation_execution_strategy.rb +1 -1
- data/lib/graphql/batch/promise.rb +3 -5
- data/lib/graphql/batch/setup.rb +7 -6
- data/lib/graphql/batch/setup_multiplex.rb +3 -2
- data/lib/graphql/batch/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d459ffa3cad4df54bc36547ef5dcc0b6f3ecf8fd
|
4
|
+
data.tar.gz: e166361d06b235a13e34c843d682d1153124b1c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f00c79b9623279179dbf000d54f1133ed0b65a73757f9c469c3643d6d64cf06139017e0eb919797368eb2f10fef252f0d4b9a1285202dce37ab0c8e767c4e3c6
|
7
|
+
data.tar.gz: b3bd7dcf7ce3d4a653f5bc46dc4ea0a4a53774be63124c7a4d94211a5af8912ef44f3801576750d7408f77422cebde292ddc1b9a02b4ad4853fb3eb6fc2be907
|
data/.travis.yml
CHANGED
data/examples/record_loader.rb
CHANGED
@@ -11,10 +11,7 @@ class RecordLoader < GraphQL::Batch::Loader
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def perform(keys)
|
14
|
-
query(keys).each
|
15
|
-
value = @column_type.cast(record.public_send(@column))
|
16
|
-
fulfill(value, record)
|
17
|
-
end
|
14
|
+
query(keys).each { |record| fulfill(record.public_send(@column), record) }
|
18
15
|
keys.each { |key| fulfill(key, nil) unless fulfilled?(key) }
|
19
16
|
end
|
20
17
|
|
data/graphql-batch.gemspec
CHANGED
@@ -21,7 +21,9 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_runtime_dependency "graphql", ">= 0.8", "< 2"
|
22
22
|
spec.add_runtime_dependency "promise.rb", "~> 0.7.2"
|
23
23
|
|
24
|
-
|
24
|
+
if RUBY_ENGINE == 'ruby' && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.2")
|
25
|
+
spec.add_development_dependency "byebug"
|
26
|
+
end
|
25
27
|
spec.add_development_dependency "bundler", "~> 1.10"
|
26
28
|
spec.add_development_dependency "rake", "~> 10.0"
|
27
29
|
spec.add_development_dependency "minitest"
|
data/lib/graphql/batch.rb
CHANGED
@@ -13,20 +13,20 @@ module GraphQL
|
|
13
13
|
raise NestedError if GraphQL::Batch::Executor.current
|
14
14
|
begin
|
15
15
|
GraphQL::Batch::Executor.current = GraphQL::Batch::Executor.new
|
16
|
-
Promise.sync(yield)
|
16
|
+
::Promise.sync(yield)
|
17
17
|
ensure
|
18
18
|
GraphQL::Batch::Executor.current = nil
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
def self.use(schema_defn)
|
22
|
+
def self.use(schema_defn, executor_class: GraphQL::Batch::Executor)
|
23
23
|
schema = schema_defn.target
|
24
24
|
if GraphQL::VERSION >= "1.6.0"
|
25
|
-
instrumentation = GraphQL::Batch::SetupMultiplex.new(schema)
|
25
|
+
instrumentation = GraphQL::Batch::SetupMultiplex.new(schema, executor_class: executor_class)
|
26
26
|
schema_defn.instrument(:multiplex, instrumentation)
|
27
27
|
schema_defn.instrument(:field, instrumentation)
|
28
28
|
else
|
29
|
-
instrumentation = GraphQL::Batch::Setup.new(schema)
|
29
|
+
instrumentation = GraphQL::Batch::Setup.new(schema, executor_class: executor_class)
|
30
30
|
schema_defn.instrument(:query, instrumentation)
|
31
31
|
schema_defn.instrument(:field, instrumentation)
|
32
32
|
end
|
@@ -11,8 +11,6 @@ module GraphQL::Batch
|
|
11
11
|
Thread.current[THREAD_KEY] = executor
|
12
12
|
end
|
13
13
|
|
14
|
-
attr_reader :loaders
|
15
|
-
|
16
14
|
# Set to true when performing a batch query, otherwise, it is false.
|
17
15
|
#
|
18
16
|
# Can be used to detect unbatched queries in an ActiveSupport::Notifications.subscribe block.
|
@@ -23,42 +21,41 @@ module GraphQL::Batch
|
|
23
21
|
@loading = false
|
24
22
|
end
|
25
23
|
|
26
|
-
def
|
27
|
-
|
24
|
+
def loader(key)
|
25
|
+
@loaders[key] ||= yield.tap do |loader|
|
26
|
+
loader.executor = self
|
27
|
+
loader.loader_key = key
|
28
|
+
end
|
28
29
|
end
|
29
30
|
|
30
|
-
def
|
31
|
-
@
|
31
|
+
def resolve(loader)
|
32
|
+
was_loading = @loading
|
33
|
+
@loading = true
|
34
|
+
loader.resolve
|
35
|
+
ensure
|
36
|
+
@loading = was_loading
|
32
37
|
end
|
33
38
|
|
34
39
|
def tick
|
35
|
-
resolve(shift)
|
40
|
+
resolve(@loaders.shift.last)
|
36
41
|
end
|
37
42
|
|
38
43
|
def wait_all
|
39
|
-
tick until loaders.empty?
|
44
|
+
tick until @loaders.empty?
|
40
45
|
end
|
41
46
|
|
42
47
|
def clear
|
43
|
-
loaders.clear
|
48
|
+
@loaders.clear
|
44
49
|
end
|
45
50
|
|
46
|
-
def
|
47
|
-
#
|
48
|
-
#
|
49
|
-
with_loading(false) { yield }
|
50
|
-
end
|
51
|
-
|
52
|
-
private
|
53
|
-
|
54
|
-
def with_loading(loading)
|
51
|
+
def around_promise_callbacks
|
52
|
+
# We need to set #loading to false so that any queries that happen in the promise
|
53
|
+
# callback aren't interpreted as being performed in GraphQL::Batch::Loader#perform
|
55
54
|
was_loading = @loading
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
@loading = was_loading
|
61
|
-
end
|
55
|
+
@loading = false
|
56
|
+
yield
|
57
|
+
ensure
|
58
|
+
@loading = was_loading
|
62
59
|
end
|
63
60
|
end
|
64
61
|
end
|
data/lib/graphql/batch/loader.rb
CHANGED
@@ -12,10 +12,7 @@ module GraphQL::Batch
|
|
12
12
|
" `GraphQL::Batch::Setup` as a query instrumenter if using with `graphql-ruby`"
|
13
13
|
end
|
14
14
|
|
15
|
-
executor.
|
16
|
-
loader.loader_key = loader_key
|
17
|
-
loader.executor = executor
|
18
|
-
end
|
15
|
+
executor.loader(loader_key) { new(*group_args) }
|
19
16
|
end
|
20
17
|
|
21
18
|
def self.loader_key_for(*group_args)
|
@@ -35,7 +32,7 @@ module GraphQL::Batch
|
|
35
32
|
def load(key)
|
36
33
|
cache[cache_key(key)] ||= begin
|
37
34
|
queue << key
|
38
|
-
Promise.new.tap { |promise| promise.source = self }
|
35
|
+
::Promise.new.tap { |promise| promise.source = self }
|
39
36
|
end
|
40
37
|
end
|
41
38
|
|
@@ -50,9 +47,7 @@ module GraphQL::Batch
|
|
50
47
|
perform(load_keys)
|
51
48
|
check_for_broken_promises(load_keys)
|
52
49
|
rescue => err
|
53
|
-
|
54
|
-
promise.reject(err)
|
55
|
-
end
|
50
|
+
reject_pending_promises
|
56
51
|
end
|
57
52
|
|
58
53
|
# For Promise#sync
|
@@ -72,7 +67,15 @@ module GraphQL::Batch
|
|
72
67
|
|
73
68
|
# Fulfill the key with provided value, for use in #perform
|
74
69
|
def fulfill(key, value)
|
75
|
-
|
70
|
+
finish_resolve(key) do |promise|
|
71
|
+
promise.fulfill(value)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def reject(key, reason)
|
76
|
+
finish_resolve(key) do |promise|
|
77
|
+
promise.reject(reason)
|
78
|
+
end
|
76
79
|
end
|
77
80
|
|
78
81
|
# Returns true when the key has already been fulfilled, otherwise returns false
|
@@ -92,6 +95,14 @@ module GraphQL::Batch
|
|
92
95
|
|
93
96
|
private
|
94
97
|
|
98
|
+
def finish_resolve(key)
|
99
|
+
promise = promise_for(key)
|
100
|
+
return yield(promise) unless executor
|
101
|
+
executor.around_promise_callbacks do
|
102
|
+
yield promise
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
95
106
|
def cache
|
96
107
|
@cache ||= {}
|
97
108
|
end
|
@@ -104,18 +115,16 @@ module GraphQL::Batch
|
|
104
115
|
cache.fetch(cache_key(load_key))
|
105
116
|
end
|
106
117
|
|
107
|
-
def
|
118
|
+
def reject_pending_promises
|
108
119
|
load_keys.each do |key|
|
109
|
-
promise
|
110
|
-
|
111
|
-
yield key, promise
|
112
|
-
end
|
120
|
+
# promise.rb ignores reject if promise isn't pending
|
121
|
+
reject(key, err)
|
113
122
|
end
|
114
123
|
end
|
115
124
|
|
116
125
|
def check_for_broken_promises(load_keys)
|
117
|
-
|
118
|
-
|
126
|
+
load_keys.each do |key|
|
127
|
+
reject(key, ::Promise::BrokenError.new("#{self.class} didn't fulfill promise for key #{key.inspect}"))
|
119
128
|
end
|
120
129
|
end
|
121
130
|
end
|
@@ -12,7 +12,7 @@ module GraphQL::Batch
|
|
12
12
|
GraphQL::Batch::Executor.current.clear
|
13
13
|
begin
|
14
14
|
strategy.enable_batching = true
|
15
|
-
strategy.deep_sync(Promise.sync(super))
|
15
|
+
strategy.deep_sync(::Promise.sync(super))
|
16
16
|
ensure
|
17
17
|
strategy.enable_batching = false
|
18
18
|
GraphQL::Batch::Executor.current.clear
|
@@ -1,8 +1,6 @@
|
|
1
1
|
module GraphQL::Batch
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
executor ? executor.defer { super } : super
|
6
|
-
end
|
2
|
+
Promise = ::Promise
|
3
|
+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.3")
|
4
|
+
deprecate_constant :Promise
|
7
5
|
end
|
8
6
|
end
|
data/lib/graphql/batch/setup.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module GraphQL::Batch
|
2
2
|
class Setup
|
3
3
|
class << self
|
4
|
-
def start_batching
|
4
|
+
def start_batching(executor_class)
|
5
5
|
raise NestedError if GraphQL::Batch::Executor.current
|
6
|
-
GraphQL::Batch::Executor.current =
|
6
|
+
GraphQL::Batch::Executor.current = executor_class.new
|
7
7
|
end
|
8
8
|
|
9
9
|
def end_batching
|
@@ -17,7 +17,7 @@ module GraphQL::Batch
|
|
17
17
|
resolve ->(obj, args, ctx) {
|
18
18
|
GraphQL::Batch::Executor.current.clear
|
19
19
|
begin
|
20
|
-
Promise.sync(old_resolve_proc.call(obj, args, ctx))
|
20
|
+
::Promise.sync(old_resolve_proc.call(obj, args, ctx))
|
21
21
|
ensure
|
22
22
|
GraphQL::Batch::Executor.current.clear
|
23
23
|
end
|
@@ -27,7 +27,7 @@ module GraphQL::Batch
|
|
27
27
|
|
28
28
|
def before_query(query)
|
29
29
|
warn "Deprecated graphql-batch setup `instrument(:query, GraphQL::Batch::Setup)`, replace with `use GraphQL::Batch`"
|
30
|
-
start_batching
|
30
|
+
start_batching(GraphQL::Batch::Executor)
|
31
31
|
end
|
32
32
|
|
33
33
|
def after_query(query)
|
@@ -35,12 +35,13 @@ module GraphQL::Batch
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
def initialize(schema)
|
38
|
+
def initialize(schema, executor_class:)
|
39
39
|
@schema = schema
|
40
|
+
@executor_class = executor_class
|
40
41
|
end
|
41
42
|
|
42
43
|
def before_query(query)
|
43
|
-
Setup.start_batching
|
44
|
+
Setup.start_batching(@executor_class)
|
44
45
|
end
|
45
46
|
|
46
47
|
def after_query(query)
|
@@ -1,11 +1,12 @@
|
|
1
1
|
module GraphQL::Batch
|
2
2
|
class SetupMultiplex
|
3
|
-
def initialize(schema)
|
3
|
+
def initialize(schema, executor_class:)
|
4
4
|
@schema = schema
|
5
|
+
@executor_class = executor_class
|
5
6
|
end
|
6
7
|
|
7
8
|
def before_multiplex(multiplex)
|
8
|
-
Setup.start_batching
|
9
|
+
Setup.start_batching(@executor_class)
|
9
10
|
end
|
10
11
|
|
11
12
|
def after_multiplex(multiplex)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql-batch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dylan Thacker-Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|
@@ -148,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
148
|
version: '0'
|
149
149
|
requirements: []
|
150
150
|
rubyforge_project:
|
151
|
-
rubygems_version: 2.5.2
|
151
|
+
rubygems_version: 2.5.2.1
|
152
152
|
signing_key:
|
153
153
|
specification_version: 4
|
154
154
|
summary: A query batching executor for the graphql gem
|