graphql-fragment_cache 1.2.0 → 1.3.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8454e3e398cc31081e2b17fb4a9b9e971cfbd1da05bce06149e419bb0e6b6b36
|
4
|
+
data.tar.gz: f654d30606764307daad38b45921533edba92fa2cd95a75556488985bd78a590
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a573a48cfe5b5d1beebd665c09b8adc4fe7d7a4bb08b29cc923c2434d921c0e9eb2c46b317d4d44367e46d0afafd2a686a0186cfb68f50459eaad2707f3da72
|
7
|
+
data.tar.gz: 2db445bfbf4ef1cd56d715e586a6c0b748695e022ac55d94bc8bd52171221902fa562426c8a53cadb2e7d0ee7667dd866f27106fb3901247932e1b1a2e3320b6
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
+
## 1.3.0 (2020-11-25)
|
6
|
+
|
7
|
+
- [PR#39](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/39) Implement `path_cache_key` option ([@DmitryTsepelev][])
|
8
|
+
|
5
9
|
## 1.2.0 (2020-10-26)
|
6
10
|
|
7
11
|
- [PR#37](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/37) Try to use `cache_key_with_version` or `cache_key` with Rails CacheKeyBuilder ([@bbugh][])
|
data/README.md
CHANGED
@@ -115,7 +115,7 @@ query_cache_key = Digest::SHA1.hexdigest("#{path_cache_key}#{selections_cache_ke
|
|
115
115
|
cache_key = "#{schema_cache_key}/#{query_cache_key}"
|
116
116
|
```
|
117
117
|
|
118
|
-
You can override `schema_cache_key` or `
|
118
|
+
You can override `schema_cache_key`, `query_cache_key` or `path_cache_key` by passing parameters to the `cache_fragment` calls:
|
119
119
|
|
120
120
|
```ruby
|
121
121
|
class QueryType < BaseObject
|
@@ -129,6 +129,8 @@ class QueryType < BaseObject
|
|
129
129
|
end
|
130
130
|
```
|
131
131
|
|
132
|
+
Overriding `path_cache_key` might be helpful when you resolve the same object nested in multiple places (e.g., `Post` and `Comment` both have `author`), but want to make sure cache will be invalidated when selection set is different.
|
133
|
+
|
132
134
|
Same for the option:
|
133
135
|
|
134
136
|
```ruby
|
@@ -141,20 +141,22 @@ module GraphQL
|
|
141
141
|
end
|
142
142
|
|
143
143
|
def path_cache_key
|
144
|
-
|
144
|
+
@options.fetch(:path_cache_key) do
|
145
|
+
lookahead = query.lookahead
|
145
146
|
|
146
|
-
|
147
|
-
|
148
|
-
|
147
|
+
path.map { |field_name|
|
148
|
+
# Handle cached fields inside collections:
|
149
|
+
next field_name if field_name.is_a?(Integer)
|
149
150
|
|
150
|
-
|
151
|
-
|
151
|
+
lookahead = lookahead.selection_with_alias(field_name)
|
152
|
+
raise "Failed to look ahead the field: #{field_name}" if lookahead.is_a?(::GraphQL::Execution::Lookahead::NullLookahead)
|
152
153
|
|
153
|
-
|
154
|
+
next lookahead.field.name if lookahead.arguments.empty?
|
154
155
|
|
155
|
-
|
156
|
-
|
157
|
-
|
156
|
+
args = lookahead.arguments.map { |_1, _2| "#{_1}:#{traverse_argument(_2)}" }.sort.join(",")
|
157
|
+
"#{lookahead.field.name}(#{args})"
|
158
|
+
}.join("/")
|
159
|
+
end
|
158
160
|
end
|
159
161
|
|
160
162
|
def traverse_argument(argument)
|
@@ -141,20 +141,22 @@ module GraphQL
|
|
141
141
|
end
|
142
142
|
|
143
143
|
def path_cache_key
|
144
|
-
|
144
|
+
@options.fetch(:path_cache_key) do
|
145
|
+
lookahead = query.lookahead
|
145
146
|
|
146
|
-
|
147
|
-
|
148
|
-
|
147
|
+
path.map { |field_name|
|
148
|
+
# Handle cached fields inside collections:
|
149
|
+
next field_name if field_name.is_a?(Integer)
|
149
150
|
|
150
|
-
|
151
|
-
|
151
|
+
lookahead = lookahead.selection_with_alias(field_name)
|
152
|
+
raise "Failed to look ahead the field: #{field_name}" if lookahead.is_a?(::GraphQL::Execution::Lookahead::NullLookahead)
|
152
153
|
|
153
|
-
|
154
|
+
next lookahead.field.name if lookahead.arguments.empty?
|
154
155
|
|
155
|
-
|
156
|
-
|
157
|
-
|
156
|
+
args = lookahead.arguments.map { "#{_1}:#{traverse_argument(_2)}" }.sort.join(",")
|
157
|
+
"#{lookahead.field.name}(#{args})"
|
158
|
+
}.join("/")
|
159
|
+
end
|
158
160
|
end
|
159
161
|
|
160
162
|
def traverse_argument(argument)
|
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.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DmitryTsepelev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|