graphql-batch 0.5.2 → 0.5.3
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 +2 -2
- data/.github/workflows/cla.yml +22 -0
- 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/version.rb +1 -1
- 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: 7c697b54ac680478b01f6ec5dbbd9f0aa60f4a7b0254b801ebf4fd24eed304b5
|
4
|
+
data.tar.gz: aedf76281ad239e034365c40d90e6460e347f896838b29e56dae07506c585103
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12da2909740747a98ceb210fc9d6ce32dcbfb21db367b818523e26efd1b96fefeee7d8b18bdb906fa1e8ca60687732b478c4f08c515d9ef82d4e73a915d03a15
|
7
|
+
data.tar.gz: 03d064a71e246df757cf4a0eed81f230082fb2efcf87b5db021a6debff7b39e693eba4895412151e5a69224c997cd829a729d735d98ca50863ea3bbb3c19bed4
|
data/.github/workflows/ci.yml
CHANGED
@@ -10,8 +10,8 @@ jobs:
|
|
10
10
|
strategy:
|
11
11
|
fail-fast: false
|
12
12
|
matrix:
|
13
|
-
ruby: [2.4, 2.7, '3.1']
|
14
|
-
graphql_version: ['~> 1.
|
13
|
+
ruby: [2.4, 2.7, '3.1', '3.2']
|
14
|
+
graphql_version: ['~> 1.12.18', '~> 1.13', '~> 2.0']
|
15
15
|
steps:
|
16
16
|
- uses: actions/checkout@v2
|
17
17
|
- 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 }}
|
@@ -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
|
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.3
|
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: 2023-
|
11
|
+
date: 2023-05-16 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.4.13
|
140
141
|
signing_key:
|
141
142
|
specification_version: 4
|
142
143
|
summary: A query batching executor for the graphql gem
|