graphql-batch 0.5.4 → 0.6.0

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: d554444b8de82eddc177ef4461270ed6b34c24e7d48f505c9b568115b913ec18
4
- data.tar.gz: e46587c28fdf154c6747b658d6ec534d2bc8d036bcef02a5fa11e52b0dc0cb9d
3
+ metadata.gz: afe26d607949310c337c3f88cb6f356ccd51923d841fa1e7e8840f0fa5b34012
4
+ data.tar.gz: 1f45b62562ef558a6f6b59479b198fdb548b8f03f061ebb0e6c51b6cff74c6b4
5
5
  SHA512:
6
- metadata.gz: 58d680e45da55224d58709d78ae187623d096dfc695b1ea8e00116590fafcd4f16b3f84ef78a337fbde0ca449c02822d87da6ce0274818cc8df336dbe016ee27
7
- data.tar.gz: 3b609c6ad409cc48deeb71d2d0d487f1fd10063f54aae181dbec7da5825deab825900fa6764634aceae2663ee05ac0a8bfdec8148a970a0d677b0f9f5bf8455d
6
+ metadata.gz: 7416844cffe48e01ca8640382e831cafdd1d64efcbcb927677a2d8833a3883400806cb94f16c8057d9c0f15ca543640b8084ba7616bb2b7376fa21f75a366179
7
+ data.tar.gz: 7473cb5eb3893fc61b0be940c28a8582a3316e912909ec7d2c8d1aeb9f01b1011b88c3ca754330f48152276ed0463e39508b625b5351800a53254dfc86669e5f
data/README.md CHANGED
@@ -140,6 +140,22 @@ def product(id:)
140
140
  end
141
141
  ```
142
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
+
143
159
  ## Unit Testing
144
160
 
145
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
@@ -1,5 +1,5 @@
1
1
  module GraphQL
2
2
  module Batch
3
- VERSION = "0.5.4"
3
+ VERSION = "0.6.0"
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.4
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: 2024-02-01 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.5.5
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