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 +4 -4
- data/README.md +16 -0
- data/lib/graphql/batch/loader.rb +4 -0
- data/lib/graphql/batch/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afe26d607949310c337c3f88cb6f356ccd51923d841fa1e7e8840f0fa5b34012
|
4
|
+
data.tar.gz: 1f45b62562ef558a6f6b59479b198fdb548b8f03f061ebb0e6c51b6cff74c6b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/graphql/batch/loader.rb
CHANGED
@@ -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
|
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.
|
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-
|
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.
|
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
|