graphql-fragment_cache 1.16.0 → 1.18.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/CHANGELOG.md +8 -0
- data/README.md +3 -7
- data/lib/.rbnext/2.3/graphql/fragment_cache/cache_key_builder.rb +14 -4
- data/lib/.rbnext/2.3/graphql/fragment_cache/memory_store.rb +2 -1
- data/lib/.rbnext/2.7/graphql/fragment_cache/cache_key_builder.rb +14 -4
- data/lib/graphql/fragment_cache/cache_key_builder.rb +14 -4
- data/lib/graphql/fragment_cache/cacher.rb +3 -3
- data/lib/graphql/fragment_cache/field_extension.rb +1 -1
- data/lib/graphql/fragment_cache/memory_store.rb +2 -1
- data/lib/graphql/fragment_cache/object_helpers.rb +3 -3
- data/lib/graphql/fragment_cache/schema/lazy_cache_resolver.rb +1 -1
- data/lib/graphql/fragment_cache/version.rb +1 -1
- data/lib/graphql/fragment_cache.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e48196795d709c0be05c78989abeb3cd3f185f6d0545d4fe3719861dabb4456
|
4
|
+
data.tar.gz: e9efc489b2e3dd907e16db7c63930d8d7251096287c369122401221a97890946
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ef9f0b47cf0c465c692d7624db882b99e746be3412345d2ce5e2b77a8c6754323fe7c784eea345b1a7b91cf07b0c2bec4fc737299f0c97fa3dce5fb5bde0797
|
7
|
+
data.tar.gz: e7024e141fd80a08d30eea830812297b82737c2204c024c4375aacdaff4524baebc44c62506a3df62b947142e57463d0adf714c1f4ff1b4b3ec4d58dee785a5a
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,14 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
+
## 1.18.0 (2022-12-28)
|
6
|
+
|
7
|
+
- [PR#94](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/94) Ruby 3 support ([@DmitryTsepelev][])
|
8
|
+
|
9
|
+
## 1.17.0 (2022-11-09)
|
10
|
+
|
11
|
+
- [PR#92](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/92) Make cache keys human-readable ([@jeromedalbert][])
|
12
|
+
|
5
13
|
## 1.16.0 (2022-11-06)
|
6
14
|
|
7
15
|
- [PR#42](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/42) Raise helpful errors when write or write_multi fails ([@DmitryTsepelev][])
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# GraphQL::FragmentCache  
|
2
2
|
|
3
3
|
`GraphQL::FragmentCache` powers up [graphql-ruby](https://graphql-ruby.org) with the ability to cache response _fragments_: you can mark any field as cached and it will never be resolved again (at least, while cache is valid). For instance, the following code caches `title` for each post:
|
4
4
|
|
@@ -9,12 +9,6 @@ class PostType < BaseObject
|
|
9
9
|
end
|
10
10
|
```
|
11
11
|
|
12
|
-
<p align="center">
|
13
|
-
<a href="https://evilmartians.com/?utm_source=graphql-ruby-fragment_cache">
|
14
|
-
<img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54">
|
15
|
-
</a>
|
16
|
-
</p>
|
17
|
-
|
18
12
|
## Getting started
|
19
13
|
|
20
14
|
Add the gem to your Gemfile `gem 'graphql-fragment_cache'` and add the plugin to your schema class:
|
@@ -489,6 +483,8 @@ end
|
|
489
483
|
|
490
484
|
Based on the original [gist](https://gist.github.com/palkan/faad9f6ff1db16fcdb1c071ec50e4190) by [@palkan](https://github.com/palkan) and [@ssnickolay](https://github.com/ssnickolay).
|
491
485
|
|
486
|
+
Initially sponsored by [Evil Martians](http://evilmartians.com).
|
487
|
+
|
492
488
|
## Contributing
|
493
489
|
|
494
490
|
Bug reports and pull requests are welcome on GitHub at [https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache).
|
@@ -128,7 +128,7 @@ module GraphQL
|
|
128
128
|
|
129
129
|
attr_reader :query, :path, :object, :schema
|
130
130
|
|
131
|
-
def initialize(object: nil,
|
131
|
+
def initialize(query:, path:, object: nil, **options)
|
132
132
|
@object = object
|
133
133
|
@query = query
|
134
134
|
@schema = query.schema
|
@@ -137,11 +137,17 @@ module GraphQL
|
|
137
137
|
end
|
138
138
|
|
139
139
|
def build
|
140
|
-
[
|
140
|
+
key_parts = [
|
141
141
|
GraphQL::FragmentCache.namespace,
|
142
|
+
simple_path_cache_key,
|
142
143
|
implicit_cache_key,
|
143
144
|
object_cache_key
|
144
|
-
]
|
145
|
+
]
|
146
|
+
|
147
|
+
key_parts
|
148
|
+
.compact
|
149
|
+
.map { |key_part| key_part.tr("/", "-") }
|
150
|
+
.join("/")
|
145
151
|
end
|
146
152
|
|
147
153
|
private
|
@@ -170,8 +176,12 @@ module GraphQL
|
|
170
176
|
current_root.selections.to_selections_key
|
171
177
|
end
|
172
178
|
|
179
|
+
def simple_path_cache_key
|
180
|
+
path_cache_key.split("(").first
|
181
|
+
end
|
182
|
+
|
173
183
|
def path_cache_key
|
174
|
-
@options.fetch(:path_cache_key) do
|
184
|
+
@path_cache_key ||= @options.fetch(:path_cache_key) do
|
175
185
|
lookahead = query.lookahead
|
176
186
|
|
177
187
|
path.map { |field_name|
|
@@ -42,7 +42,8 @@ module GraphQL
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
def write(key, value,
|
45
|
+
def write(key, value, options = {})
|
46
|
+
expires_in = options[:expires_in] || default_expires_in
|
46
47
|
key = key.to_s
|
47
48
|
@storage[key] = Entry.new(value: value, expires_at: expires_in ? Time.now + expires_in : nil)
|
48
49
|
end
|
@@ -128,7 +128,7 @@ module GraphQL
|
|
128
128
|
|
129
129
|
attr_reader :query, :path, :object, :schema
|
130
130
|
|
131
|
-
def initialize(object: nil,
|
131
|
+
def initialize(query:, path:, object: nil, **options)
|
132
132
|
@object = object
|
133
133
|
@query = query
|
134
134
|
@schema = query.schema
|
@@ -137,11 +137,17 @@ module GraphQL
|
|
137
137
|
end
|
138
138
|
|
139
139
|
def build
|
140
|
-
[
|
140
|
+
key_parts = [
|
141
141
|
GraphQL::FragmentCache.namespace,
|
142
|
+
simple_path_cache_key,
|
142
143
|
implicit_cache_key,
|
143
144
|
object_cache_key
|
144
|
-
]
|
145
|
+
]
|
146
|
+
|
147
|
+
key_parts
|
148
|
+
.compact
|
149
|
+
.map { |key_part| key_part.tr("/", "-") }
|
150
|
+
.join("/")
|
145
151
|
end
|
146
152
|
|
147
153
|
private
|
@@ -170,8 +176,12 @@ module GraphQL
|
|
170
176
|
current_root.selections.to_selections_key
|
171
177
|
end
|
172
178
|
|
179
|
+
def simple_path_cache_key
|
180
|
+
path_cache_key.split("(").first
|
181
|
+
end
|
182
|
+
|
173
183
|
def path_cache_key
|
174
|
-
@options.fetch(:path_cache_key) do
|
184
|
+
@path_cache_key ||= @options.fetch(:path_cache_key) do
|
175
185
|
lookahead = query.lookahead
|
176
186
|
|
177
187
|
path.map { |field_name|
|
@@ -128,7 +128,7 @@ module GraphQL
|
|
128
128
|
|
129
129
|
attr_reader :query, :path, :object, :schema
|
130
130
|
|
131
|
-
def initialize(object: nil,
|
131
|
+
def initialize(query:, path:, object: nil, **options)
|
132
132
|
@object = object
|
133
133
|
@query = query
|
134
134
|
@schema = query.schema
|
@@ -137,11 +137,17 @@ module GraphQL
|
|
137
137
|
end
|
138
138
|
|
139
139
|
def build
|
140
|
-
[
|
140
|
+
key_parts = [
|
141
141
|
GraphQL::FragmentCache.namespace,
|
142
|
+
simple_path_cache_key,
|
142
143
|
implicit_cache_key,
|
143
144
|
object_cache_key
|
144
|
-
]
|
145
|
+
]
|
146
|
+
|
147
|
+
key_parts
|
148
|
+
.compact
|
149
|
+
.map { |key_part| key_part.tr("/", "-") }
|
150
|
+
.join("/")
|
145
151
|
end
|
146
152
|
|
147
153
|
private
|
@@ -170,8 +176,12 @@ module GraphQL
|
|
170
176
|
current_root.selections.to_selections_key
|
171
177
|
end
|
172
178
|
|
179
|
+
def simple_path_cache_key
|
180
|
+
path_cache_key.split("(").first
|
181
|
+
end
|
182
|
+
|
173
183
|
def path_cache_key
|
174
|
-
@options.fetch(:path_cache_key) do
|
184
|
+
@path_cache_key ||= @options.fetch(:path_cache_key) do
|
175
185
|
lookahead = query.lookahead
|
176
186
|
|
177
187
|
path.map { |field_name|
|
@@ -47,7 +47,7 @@ module GraphQL
|
|
47
47
|
hash = group.map { |fragment| [fragment.cache_key, fragment.value] }.to_h
|
48
48
|
|
49
49
|
begin
|
50
|
-
FragmentCache.cache_store.write_multi(hash,
|
50
|
+
FragmentCache.cache_store.write_multi(*hash, options)
|
51
51
|
rescue => e
|
52
52
|
raise WriteMultiError.new(e, hash)
|
53
53
|
end
|
@@ -56,9 +56,9 @@ module GraphQL
|
|
56
56
|
|
57
57
|
def persist(query)
|
58
58
|
select_valid_fragments(query).each do |fragment|
|
59
|
-
FragmentCache.cache_store.write(fragment.cache_key, fragment.value,
|
59
|
+
FragmentCache.cache_store.write(fragment.cache_key, fragment.value, fragment.options)
|
60
60
|
rescue => e
|
61
|
-
raise WriteError.new(e, fragment.cache_key, fragment.value)
|
61
|
+
raise WriteError.new(e, fragment.cache_key, fragment.value), e
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
@@ -77,7 +77,7 @@ module GraphQL
|
|
77
77
|
cache_fragment_options = @cache_options.merge(object: object_for_key)
|
78
78
|
|
79
79
|
object.cache_fragment(**cache_fragment_options) do
|
80
|
-
resolved_value == NOT_RESOLVED ? yield(object, arguments) : resolved_value
|
80
|
+
(resolved_value == NOT_RESOLVED) ? yield(object, arguments) : resolved_value
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|
@@ -42,7 +42,8 @@ module GraphQL
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
def write(key, value,
|
45
|
+
def write(key, value, options = {})
|
46
|
+
expires_in = options[:expires_in] || default_expires_in
|
46
47
|
key = key.to_s
|
47
48
|
@storage[key] = Entry.new(value: value, expires_at: expires_in ? Time.now + expires_in : nil)
|
48
49
|
end
|
@@ -24,9 +24,9 @@ module GraphQL
|
|
24
24
|
NO_OBJECT = Object.new
|
25
25
|
|
26
26
|
def cache_fragment(object_to_cache = NO_OBJECT, **options, &block)
|
27
|
-
raise ArgumentError, "Block or argument must be provided" unless
|
27
|
+
raise ArgumentError, "Block or argument must be provided" unless block || object_to_cache != NO_OBJECT
|
28
28
|
unless GraphQL::FragmentCache.enabled
|
29
|
-
return
|
29
|
+
return block ? block.call : object_to_cache
|
30
30
|
end
|
31
31
|
|
32
32
|
unless options.delete(:default_options_merged)
|
@@ -36,7 +36,7 @@ module GraphQL
|
|
36
36
|
if options.key?(:if) || options.key?(:unless)
|
37
37
|
disabled = options.key?(:if) ? !options.delete(:if) : options.delete(:unless)
|
38
38
|
if disabled
|
39
|
-
return
|
39
|
+
return block ? block.call : object_to_cache
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -28,7 +28,7 @@ module GraphQL
|
|
28
28
|
cached = @lazy_state[:resolved_fragments][@fragment]
|
29
29
|
|
30
30
|
if cached
|
31
|
-
return cached == Fragment::NIL_IN_CACHE ? nil : GraphQL::Execution::Interpreter::RawValue.new(cached)
|
31
|
+
return (cached == Fragment::NIL_IN_CACHE) ? nil : GraphQL::Execution::Interpreter::RawValue.new(cached)
|
32
32
|
end
|
33
33
|
|
34
34
|
(@block ? @block.call : @object_to_cache).tap do |resolved_value|
|
@@ -55,7 +55,7 @@ module GraphQL
|
|
55
55
|
@cache_store = store
|
56
56
|
end
|
57
57
|
|
58
|
-
|
58
|
+
alias_method :skip_cache_when_query_has_errors?, :skip_cache_when_query_has_errors
|
59
59
|
|
60
60
|
def graphql_ruby_before_2_0?
|
61
61
|
check_graphql_version "< 2.0.0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.18.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DmitryTsepelev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|
@@ -170,14 +170,14 @@ dependencies:
|
|
170
170
|
requirements:
|
171
171
|
- - '='
|
172
172
|
- !ruby/object:Gem::Version
|
173
|
-
version: 3.
|
173
|
+
version: 3.1.2.1
|
174
174
|
type: :development
|
175
175
|
prerelease: false
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
178
|
- - '='
|
179
179
|
- !ruby/object:Gem::Version
|
180
|
-
version: 3.
|
180
|
+
version: 3.1.2.1
|
181
181
|
description: Fragment cache for graphql-ruby
|
182
182
|
email:
|
183
183
|
- dmitry.a.tsepelev@gmail.com
|
@@ -235,7 +235,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
235
235
|
- !ruby/object:Gem::Version
|
236
236
|
version: '0'
|
237
237
|
requirements: []
|
238
|
-
rubygems_version: 3.
|
238
|
+
rubygems_version: 3.4.1
|
239
239
|
signing_key:
|
240
240
|
specification_version: 4
|
241
241
|
summary: Fragment cache for graphql-ruby
|