graphql-batch 0.5.2 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +7 -2
- data/.github/workflows/cla.yml +22 -0
- data/README.md +1 -3
- data/examples/active_storage_loader.rb +3 -3
- data/examples/http_loader.rb +8 -1
- data/graphql-batch.gemspec +1 -1
- data/lib/graphql/batch/loader.rb +10 -1
- data/lib/graphql/batch/setup_multiplex.rb +14 -0
- data/lib/graphql/batch/version.rb +1 -1
- data/lib/graphql/batch.rb +6 -2
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d554444b8de82eddc177ef4461270ed6b34c24e7d48f505c9b568115b913ec18
|
4
|
+
data.tar.gz: e46587c28fdf154c6747b658d6ec534d2bc8d036bcef02a5fa11e52b0dc0cb9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58d680e45da55224d58709d78ae187623d096dfc695b1ea8e00116590fafcd4f16b3f84ef78a337fbde0ca449c02822d87da6ce0274818cc8df336dbe016ee27
|
7
|
+
data.tar.gz: 3b609c6ad409cc48deeb71d2d0d487f1fd10063f54aae181dbec7da5825deab825900fa6764634aceae2663ee05ac0a8bfdec8148a970a0d677b0f9f5bf8455d
|
data/.github/workflows/ci.yml
CHANGED
@@ -10,8 +10,13 @@ jobs:
|
|
10
10
|
strategy:
|
11
11
|
fail-fast: false
|
12
12
|
matrix:
|
13
|
-
ruby: [2.
|
14
|
-
graphql_version: ['~> 1.
|
13
|
+
ruby: [2.7, 3.1, 3.3]
|
14
|
+
graphql_version: ['~> 1.12.18', '~> 1.13', '~> 2.0']
|
15
|
+
include:
|
16
|
+
- ruby: 2.4
|
17
|
+
graphql_version: '~> 1.12.18'
|
18
|
+
- ruby: 2.4
|
19
|
+
graphql_version: '~> 1.13'
|
15
20
|
steps:
|
16
21
|
- uses: actions/checkout@v2
|
17
22
|
- uses: ruby/setup-ruby@v1
|
@@ -0,0 +1,22 @@
|
|
1
|
+
name: Contributor License Agreement (CLA)
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request_target:
|
5
|
+
types: [opened, synchronize]
|
6
|
+
issue_comment:
|
7
|
+
types: [created]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
cla:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
if: |
|
13
|
+
(github.event.issue.pull_request
|
14
|
+
&& !github.event.issue.pull_request.merged_at
|
15
|
+
&& contains(github.event.comment.body, 'signed')
|
16
|
+
)
|
17
|
+
|| (github.event.pull_request && !github.event.pull_request.merged)
|
18
|
+
steps:
|
19
|
+
- uses: Shopify/shopify-cla-action@v1
|
20
|
+
with:
|
21
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
22
|
+
cla-token: ${{ secrets.CLA_TOKEN }}
|
data/README.md
CHANGED
@@ -122,9 +122,7 @@ def all_collections
|
|
122
122
|
Promise.all([
|
123
123
|
CountLoader.for(Shop, :smart_collections).load(context.shop_id),
|
124
124
|
CountLoader.for(Shop, :custom_collections).load(context.shop_id),
|
125
|
-
]).then
|
126
|
-
results.reduce(&:+)
|
127
|
-
end
|
125
|
+
]).then(&:sum)
|
128
126
|
end
|
129
127
|
```
|
130
128
|
|
@@ -14,7 +14,7 @@
|
|
14
14
|
# end
|
15
15
|
|
16
16
|
####
|
17
|
-
# An example data type using the
|
17
|
+
# An example data type using the Loaders::ActiveStorageLoader
|
18
18
|
####
|
19
19
|
|
20
20
|
# class Types::EventType < Types::BaseObject
|
@@ -25,7 +25,7 @@
|
|
25
25
|
# field :pictures, String, null: true
|
26
26
|
#
|
27
27
|
# def image
|
28
|
-
#
|
28
|
+
# Loaders::ActiveStorageLoader.for(:Event, :image).load(object.id).then do |image|
|
29
29
|
# Rails.application.routes.url_helpers.url_for(
|
30
30
|
# image.variant({ quality: 75 })
|
31
31
|
# )
|
@@ -33,7 +33,7 @@
|
|
33
33
|
# end
|
34
34
|
#
|
35
35
|
# def pictures
|
36
|
-
#
|
36
|
+
# Loaders::ActiveStorageLoader.for(:Event, :pictures, association_type: :has_many_attached).load(object.id).then do |pictures|
|
37
37
|
# pictures.map do |picture|
|
38
38
|
# Rails.application.routes.url_helpers.url_for(
|
39
39
|
# picture.variant({ quality: 75 })
|
data/examples/http_loader.rb
CHANGED
@@ -35,6 +35,7 @@
|
|
35
35
|
# }
|
36
36
|
# GQL
|
37
37
|
|
38
|
+
# An example loader which is blocking and synchronous as a whole, but executes all of its operations concurrently.
|
38
39
|
module Loaders
|
39
40
|
class HTTPLoader < GraphQL::Batch::Loader
|
40
41
|
def initialize(host:, size: 4, timeout: 4)
|
@@ -45,13 +46,19 @@ module Loaders
|
|
45
46
|
end
|
46
47
|
|
47
48
|
def perform(operations)
|
49
|
+
# This fans out and starts off all the concurrent work, which starts and
|
50
|
+
# immediately returns Concurrent::Promises::Future` objects for each operation.
|
48
51
|
futures = operations.map do |operation|
|
49
52
|
Concurrent::Promises.future do
|
50
53
|
pool.with { |connection| operation.call(connection) }
|
51
54
|
end
|
52
55
|
end
|
56
|
+
# At this point, all of the concurrent work has been started.
|
57
|
+
|
58
|
+
# This converges back in, waiting on each concurrent future to finish, and fulfilling each
|
59
|
+
# (non-concurrent) Promise.rb promise.
|
53
60
|
operations.each_with_index.each do |operation, index|
|
54
|
-
fulfill(operation, futures[index].value)
|
61
|
+
fulfill(operation, futures[index].value) # .value is a blocking call
|
55
62
|
end
|
56
63
|
end
|
57
64
|
|
data/graphql-batch.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
|
18
18
|
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
19
19
|
|
20
|
-
spec.add_runtime_dependency "graphql", ">= 1.
|
20
|
+
spec.add_runtime_dependency "graphql", ">= 1.12.18", "< 3"
|
21
21
|
spec.add_runtime_dependency "promise.rb", "~> 0.7.2"
|
22
22
|
|
23
23
|
spec.add_development_dependency "byebug" if RUBY_ENGINE == 'ruby'
|
data/lib/graphql/batch/loader.rb
CHANGED
@@ -66,12 +66,21 @@ module GraphQL::Batch
|
|
66
66
|
return if resolved?
|
67
67
|
load_keys = queue
|
68
68
|
@queue = nil
|
69
|
-
|
69
|
+
|
70
|
+
around_perform do
|
71
|
+
perform(load_keys)
|
72
|
+
end
|
73
|
+
|
70
74
|
check_for_broken_promises(load_keys)
|
71
75
|
rescue => err
|
72
76
|
reject_pending_promises(load_keys, err)
|
73
77
|
end
|
74
78
|
|
79
|
+
# Interface to add custom code for purposes such as instrumenting the performance of the loader.
|
80
|
+
def around_perform
|
81
|
+
yield
|
82
|
+
end
|
83
|
+
|
75
84
|
# For Promise#sync
|
76
85
|
def wait #:nodoc:
|
77
86
|
if executor
|
@@ -12,5 +12,19 @@ module GraphQL::Batch
|
|
12
12
|
def after_multiplex(multiplex)
|
13
13
|
GraphQL::Batch::Executor.end_batch
|
14
14
|
end
|
15
|
+
|
16
|
+
module Trace
|
17
|
+
def initialize(executor_class:, **_rest)
|
18
|
+
@executor_class = executor_class
|
19
|
+
super
|
20
|
+
end
|
21
|
+
|
22
|
+
def execute_multiplex(multiplex:)
|
23
|
+
GraphQL::Batch::Executor.start_batch(@executor_class)
|
24
|
+
super
|
25
|
+
ensure
|
26
|
+
GraphQL::Batch::Executor.end_batch
|
27
|
+
end
|
28
|
+
end
|
15
29
|
end
|
16
30
|
end
|
data/lib/graphql/batch.rb
CHANGED
@@ -16,8 +16,12 @@ module GraphQL
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.use(schema_defn, executor_class: GraphQL::Batch::Executor)
|
19
|
-
|
20
|
-
|
19
|
+
if schema_defn.respond_to?(:trace_with)
|
20
|
+
schema_defn.trace_with(GraphQL::Batch::SetupMultiplex::Trace, executor_class: executor_class)
|
21
|
+
else
|
22
|
+
instrumentation = GraphQL::Batch::SetupMultiplex.new(schema_defn, executor_class: executor_class)
|
23
|
+
schema_defn.instrument(:multiplex, instrumentation)
|
24
|
+
end
|
21
25
|
|
22
26
|
if schema_defn.mutation
|
23
27
|
require_relative "batch/mutation_field_extension"
|
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.5.
|
4
|
+
version: 0.5.4
|
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:
|
11
|
+
date: 2024-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|
@@ -16,7 +16,7 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.12.18
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '3'
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 1.12.18
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '3'
|
@@ -94,6 +94,7 @@ extensions: []
|
|
94
94
|
extra_rdoc_files: []
|
95
95
|
files:
|
96
96
|
- ".github/workflows/ci.yml"
|
97
|
+
- ".github/workflows/cla.yml"
|
97
98
|
- ".gitignore"
|
98
99
|
- ".rubocop.yml"
|
99
100
|
- ".rubocop_todo.yml"
|
@@ -136,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
137
|
- !ruby/object:Gem::Version
|
137
138
|
version: '0'
|
138
139
|
requirements: []
|
139
|
-
rubygems_version: 3.
|
140
|
+
rubygems_version: 3.5.5
|
140
141
|
signing_key:
|
141
142
|
specification_version: 4
|
142
143
|
summary: A query batching executor for the graphql gem
|