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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cadb2aa4640e2a2a7315b4a201ac2cee587d6696d49a6afe217850c710049b23
4
- data.tar.gz: 22e8303ce284034b08d3c89af261c9ca82b9f9d18f4e6d2b768ff2448e544f75
3
+ metadata.gz: 7c697b54ac680478b01f6ec5dbbd9f0aa60f4a7b0254b801ebf4fd24eed304b5
4
+ data.tar.gz: aedf76281ad239e034365c40d90e6460e347f896838b29e56dae07506c585103
5
5
  SHA512:
6
- metadata.gz: 7c17ca80df3d0433a290ebbab09dfcac5800a2eaebed9f89d5e44fb1aee098a7d5af44607e8e6a53970e457b8734ce52a176335c542a93e4f6a80e9ddbc9a2ff
7
- data.tar.gz: 262b06ce514d5028334fbf2557b7810137526d9f7dacae5e53acd2e0602dec19c6385b7f7c9f7574f2905c46d5f10df53b81b2e7c82c078642de40225eb47f3f
6
+ metadata.gz: 12da2909740747a98ceb210fc9d6ce32dcbfb21db367b818523e26efd1b96fefeee7d8b18bdb906fa1e8ca60687732b478c4f08c515d9ef82d4e73a915d03a15
7
+ data.tar.gz: 03d064a71e246df757cf4a0eed81f230082fb2efcf87b5db021a6debff7b39e693eba4895412151e5a69224c997cd829a729d735d98ca50863ea3bbb3c19bed4
@@ -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.10.0', '~> 1.13', '~> 2.0']
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 AttachmentLoader
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
- # AttachmentLoader.for(:Event, :image).load(object.id).then do |image|
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
- # AttachmentLoader.for(:Event, :pictures, association_type: :has_many_attached).load(object.id).then do |pictures|
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 })
@@ -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
 
@@ -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.10", "< 3"
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'
@@ -66,12 +66,21 @@ module GraphQL::Batch
66
66
  return if resolved?
67
67
  load_keys = queue
68
68
  @queue = nil
69
- perform(load_keys)
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
@@ -1,5 +1,5 @@
1
1
  module GraphQL
2
2
  module Batch
3
- VERSION = "0.5.2"
3
+ VERSION = "0.5.3"
4
4
  end
5
5
  end
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.2
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-01-16 00:00:00.000000000 Z
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: '1.10'
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: '1.10'
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.3.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