graphql-batch 0.5.3 → 0.6.0

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: 7c697b54ac680478b01f6ec5dbbd9f0aa60f4a7b0254b801ebf4fd24eed304b5
4
- data.tar.gz: aedf76281ad239e034365c40d90e6460e347f896838b29e56dae07506c585103
3
+ metadata.gz: afe26d607949310c337c3f88cb6f356ccd51923d841fa1e7e8840f0fa5b34012
4
+ data.tar.gz: 1f45b62562ef558a6f6b59479b198fdb548b8f03f061ebb0e6c51b6cff74c6b4
5
5
  SHA512:
6
- metadata.gz: 12da2909740747a98ceb210fc9d6ce32dcbfb21db367b818523e26efd1b96fefeee7d8b18bdb906fa1e8ca60687732b478c4f08c515d9ef82d4e73a915d03a15
7
- data.tar.gz: 03d064a71e246df757cf4a0eed81f230082fb2efcf87b5db021a6debff7b39e693eba4895412151e5a69224c997cd829a729d735d98ca50863ea3bbb3c19bed4
6
+ metadata.gz: 7416844cffe48e01ca8640382e831cafdd1d64efcbcb927677a2d8833a3883400806cb94f16c8057d9c0f15ca543640b8084ba7616bb2b7376fa21f75a366179
7
+ data.tar.gz: 7473cb5eb3893fc61b0be940c28a8582a3316e912909ec7d2c8d1aeb9f01b1011b88c3ca754330f48152276ed0463e39508b625b5351800a53254dfc86669e5f
@@ -10,8 +10,13 @@ jobs:
10
10
  strategy:
11
11
  fail-fast: false
12
12
  matrix:
13
- ruby: [2.4, 2.7, '3.1', '3.2']
13
+ ruby: [2.7, 3.1, 3.3]
14
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
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 do |results|
126
- results.reduce(&:+)
127
- end
125
+ ]).then(&:sum)
128
126
  end
129
127
  ```
130
128
 
@@ -142,6 +140,22 @@ def product(id:)
142
140
  end
143
141
  ```
144
142
 
143
+ ### Priming the Cache
144
+
145
+ You can prime the loader cache with a specific value, which can be useful in certain situations.
146
+
147
+ ```ruby
148
+ def liked_products
149
+ liked_products = Product.where(liked: true).load
150
+ liked_products.each do |product|
151
+ RecordLoader.for(Product).prime(product.id, product)
152
+ end
153
+ end
154
+ ```
155
+
156
+ Priming will add key/value to the loader cache only if it didn't exist before.
157
+
158
+
145
159
  ## Unit Testing
146
160
 
147
161
  Your loaders can be tested outside of a GraphQL query by doing the
@@ -62,6 +62,10 @@ module GraphQL::Batch
62
62
  ::Promise.all(keys.map { |key| load(key) })
63
63
  end
64
64
 
65
+ def prime(key, value)
66
+ cache[cache_key(key)] ||= ::Promise.resolve(value).tap { |p| p.source = self }
67
+ end
68
+
65
69
  def resolve #:nodoc:
66
70
  return if resolved?
67
71
  load_keys = queue
@@ -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
@@ -1,5 +1,5 @@
1
1
  module GraphQL
2
2
  module Batch
3
- VERSION = "0.5.3"
3
+ VERSION = "0.6.0"
4
4
  end
5
5
  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
- instrumentation = GraphQL::Batch::SetupMultiplex.new(schema_defn, executor_class: executor_class)
20
- schema_defn.instrument(:multiplex, instrumentation)
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.3
4
+ version: 0.6.0
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-05-16 00:00:00.000000000 Z
11
+ date: 2024-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql
@@ -137,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  requirements: []
140
- rubygems_version: 3.4.13
140
+ rubygems_version: 3.5.6
141
141
  signing_key:
142
142
  specification_version: 4
143
143
  summary: A query batching executor for the graphql gem