graphql-fragment_cache 1.21.0 → 1.22.2
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/CHANGELOG.md +9 -0
- data/README.md +28 -0
- data/lib/graphql/fragment_cache/cache_key_builder.rb +12 -2
- data/lib/graphql/fragment_cache/graphql_ruby_version.rb +4 -0
- data/lib/graphql/fragment_cache/schema/tracer.rb +1 -1
- data/lib/graphql/fragment_cache/version.rb +1 -1
- metadata +3 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b58c6a92e1599cb9096dd48fb540e221dd291a3b4864980cf7b618986cf8c1ed
|
4
|
+
data.tar.gz: 5b19fc87c04ed9a92d94cb88f354b317eaf50e77369799effbbe74b5054bf124
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c3243e15ff2abed075c7da99060ed750007aa4298d53a9e1a67ae72dd30cbde3c2a71a1c32e18bb4e6c151e6c1c0c1755c579595d6f0143a9db3b9dbcf2ab38
|
7
|
+
data.tar.gz: '0937e3232dd472d5e51c94cfb4d44b01ede12676472e125a89d4e09ab5ae5e4f2d251df58b64a6e10ad6526fc7a7297a71d98b52b98510c98c13d43f9c352508'
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,14 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
+
## 1.22.1 (2025-06-07)
|
6
|
+
|
7
|
+
- [PR#137](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/137) Remove new_connections? check for gql > 2.3.10 in Tracer ([@DmitryTsepelev][])
|
8
|
+
|
9
|
+
## 1.22.0 (2025-02-20)
|
10
|
+
|
11
|
+
- [PR#134](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/134) Add possibility to include and exclude arguments from generated cache key ([@mgruner][])
|
12
|
+
|
5
13
|
## 1.21.0 (2025-02-01)
|
6
14
|
|
7
15
|
- [PR#130](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/130) Dataloader support ([@DmitryTsepelev][])
|
@@ -217,3 +225,4 @@
|
|
217
225
|
[@noma4i]: https://github.com/noma4i
|
218
226
|
[@Drowze]: https://github.com/Drowze
|
219
227
|
[@danielhartnell]: https://github.com/danielhartnell
|
228
|
+
[@mgruner]: https://github.com/mgruner
|
data/README.md
CHANGED
@@ -147,6 +147,34 @@ class QueryType < BaseObject
|
|
147
147
|
end
|
148
148
|
```
|
149
149
|
|
150
|
+
### Query arguments processing
|
151
|
+
|
152
|
+
You can influence the way that graphql arguments are include in the cache key.
|
153
|
+
|
154
|
+
A use case might be a `:renew_cache` parameter that can be used to force a cache rewrite,
|
155
|
+
but should not be included with the cache key itself. Use `cache_key: { exclude_arguments: […]}`
|
156
|
+
to specify a list of arguments to be excluded from the implicit cache key.
|
157
|
+
|
158
|
+
```ruby
|
159
|
+
class QueryType < BaseObject
|
160
|
+
field :post, PostType, null: true do
|
161
|
+
argument :id, ID, required: true
|
162
|
+
argument :renew_cache, Boolean, required: false
|
163
|
+
end
|
164
|
+
|
165
|
+
def post(id:, renew_cache: false)
|
166
|
+
if renew_cache
|
167
|
+
context.scoped_set!(:renew_cache, true)
|
168
|
+
end
|
169
|
+
cache_fragment(cache_key: {exclude_arguments: [:renew_cache]}) { Post.find(id) }
|
170
|
+
end
|
171
|
+
end
|
172
|
+
```
|
173
|
+
|
174
|
+
Likewise, you can use `cache_key: { include_arguments: […] }` to specify an allowlist of arguments
|
175
|
+
to be included in the cache key. In this case all arguments for the cache key must be specified, including
|
176
|
+
parent arguments of nested fields.
|
177
|
+
|
150
178
|
### User-provided cache key (custom key)
|
151
179
|
|
152
180
|
In most cases you want your cache key to depend on the resolved object (say, `ActiveRecord` model). You can do that by passing an argument to the `#cache_fragment` method in a similar way to Rails views [`#cache` method](https://guides.rubyonrails.org/caching_with_rails.html#fragment-caching):
|
@@ -130,16 +130,26 @@ module GraphQL
|
|
130
130
|
|
131
131
|
next lookahead.field.name if lookahead.arguments.empty?
|
132
132
|
|
133
|
-
args = lookahead.arguments.map { "#{_1}:#{traverse_argument(_2)}" }.sort.join(",")
|
133
|
+
args = lookahead.arguments.select { include_argument?(_1) }.map { "#{_1}:#{traverse_argument(_2)}" }.sort.join(",")
|
134
134
|
"#{lookahead.field.name}(#{args})"
|
135
135
|
}.join("/")
|
136
136
|
end
|
137
137
|
end
|
138
138
|
|
139
|
+
def include_argument?(argument_name)
|
140
|
+
exclude_arguments = @options.dig(:cache_key, :exclude_arguments)
|
141
|
+
return false if exclude_arguments&.include?(argument_name)
|
142
|
+
|
143
|
+
include_arguments = @options.dig(:cache_key, :include_arguments)
|
144
|
+
return false if include_arguments && !include_arguments.include?(argument_name)
|
145
|
+
|
146
|
+
true
|
147
|
+
end
|
148
|
+
|
139
149
|
def traverse_argument(argument)
|
140
150
|
return argument unless argument.is_a?(GraphQL::Schema::InputObject)
|
141
151
|
|
142
|
-
"{#{argument.map { "#{_1}:#{traverse_argument(_2)}" }.sort.join(",")}}"
|
152
|
+
"{#{argument.map { include_argument?(_1) ? "#{_1}:#{traverse_argument(_2)}" : nil }.compact.sort.join(",")}}"
|
143
153
|
end
|
144
154
|
|
145
155
|
def object_cache_key
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql-fragment_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.22.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DmitryTsepelev
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date: 2025-
|
10
|
+
date: 2025-06-07 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: graphql
|
@@ -192,7 +191,6 @@ metadata:
|
|
192
191
|
homepage_uri: https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache
|
193
192
|
source_code_uri: https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache
|
194
193
|
changelog_uri: https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/CHANGELOG.md
|
195
|
-
post_install_message:
|
196
194
|
rdoc_options: []
|
197
195
|
require_paths:
|
198
196
|
- lib
|
@@ -207,8 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
207
205
|
- !ruby/object:Gem::Version
|
208
206
|
version: '0'
|
209
207
|
requirements: []
|
210
|
-
rubygems_version: 3.
|
211
|
-
signing_key:
|
208
|
+
rubygems_version: 3.6.2
|
212
209
|
specification_version: 4
|
213
210
|
summary: Fragment cache for graphql-ruby
|
214
211
|
test_files: []
|