graphql-batch 0.5.1 → 0.5.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47a1830934c614913132268636ef825fd7df42865c3b1d4dde4a605b29591627
4
- data.tar.gz: cd8ae5dcee54e53bb6b1b496b76387dede14bd0079bac9615b297a2a9d7aa269
3
+ metadata.gz: 7c697b54ac680478b01f6ec5dbbd9f0aa60f4a7b0254b801ebf4fd24eed304b5
4
+ data.tar.gz: aedf76281ad239e034365c40d90e6460e347f896838b29e56dae07506c585103
5
5
  SHA512:
6
- metadata.gz: 0146b5ab9acb4d952215a4ab443b4ccd4d4fbc33a5b7502a53f5ca9598be66d25f10480cf127a9871ef957a3a2ba51d9b65db096161bdd6a8b6d6fbf4d4e7cca
7
- data.tar.gz: 62d35a163c8e244943324d704f3a273d26b95df88624fbab98159f46ef725318ca3a21c7b58f909c97fc565d3638e2befca02e6cc766cd80439deaf7c93a6df1
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'
@@ -44,6 +44,13 @@ module GraphQL::Batch
44
44
 
45
45
  attr_accessor :loader_key, :executor
46
46
 
47
+ def initialize
48
+ @loader_key = nil
49
+ @executor = nil
50
+ @queue = nil
51
+ @cache = nil
52
+ end
53
+
47
54
  def load(key)
48
55
  cache[cache_key(key)] ||= begin
49
56
  queue << key
@@ -59,12 +66,21 @@ module GraphQL::Batch
59
66
  return if resolved?
60
67
  load_keys = queue
61
68
  @queue = nil
62
- perform(load_keys)
69
+
70
+ around_perform do
71
+ perform(load_keys)
72
+ end
73
+
63
74
  check_for_broken_promises(load_keys)
64
75
  rescue => err
65
76
  reject_pending_promises(load_keys, err)
66
77
  end
67
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
+
68
84
  # For Promise#sync
69
85
  def wait #:nodoc:
70
86
  if executor
@@ -1,5 +1,5 @@
1
1
  module GraphQL
2
2
  module Batch
3
- VERSION = "0.5.1"
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.1
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: 2022-02-25 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.2.20
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