graphql-fragment_cache 1.16.0 → 1.17.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3bcaf1bb938f830b5ae34b7b034e2ccbf8ce139e5da10db08e8ca52b658c0ed3
4
- data.tar.gz: 5842f5166dc9cf69a276b3dee9836a43b757485ffe46f54031ce42341dfe797a
3
+ metadata.gz: e2c544bc2742643748c5e36c59b3414def73c22e6f7c4b5080504751ea564ecd
4
+ data.tar.gz: b61980525863502ea4f30eeb96fee11dbc11a906ab98b863ed0ece7f9d97d1e9
5
5
  SHA512:
6
- metadata.gz: e218c2d46cb5cc545d0374c86c64f46380b82a4c31dd67d0dcb06890e23c4156ed16cef838d3965ae54283e28ea7ba155d965920dbc1c9a722a64fff7c174b69
7
- data.tar.gz: caa35cd10a7c657b838088b0ffd449b981ee3565483691619af1c839a184febccacf19620c31bfee26f434929218e2ecd4478a6edbca7bf97ae3a68245bbe316
6
+ metadata.gz: aac16bb6d2541e573796043ebf2da2ffa171918730ad95f4613db1f6b20cb1156a4a1cb3d70b7e0c39be57a6d56d2cfd3a27d95470c0c316f8f95a756bf83377
7
+ data.tar.gz: 85349b218d754a716db3aa8165e8de64a92b48c22e4b4b1615e612d041000701a090c643fa6b6e68326bb51a3688df2eb71f84604a1bfd19034eb01201453b26
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 1.17.0 (2022-11-09)
6
+
7
+ - [PR#92](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/92) Make cache keys human-readable ([@jeromedalbert][])
8
+
5
9
  ## 1.16.0 (2022-11-06)
6
10
 
7
11
  - [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 ![CI](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/workflows/CI/badge.svg?branch=master)
1
+ # GraphQL::FragmentCache ![CI](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/actions/workflows/rspec.yml/badge.svg?branch=master) ![](https://ruby-gem-downloads-badge.herokuapp.com/graphql-fragment_cache?type=total)
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).
@@ -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
- ].compact.join("/")
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,22 +176,28 @@ 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
175
- lookahead = query.lookahead
184
+ @path_cache_key ||= begin
185
+ @options.fetch(:path_cache_key) do
186
+ lookahead = query.lookahead
176
187
 
177
- path.map { |field_name|
178
- # Handle cached fields inside collections:
179
- next field_name if field_name.is_a?(Integer)
188
+ path.map { |field_name|
189
+ # Handle cached fields inside collections:
190
+ next field_name if field_name.is_a?(Integer)
180
191
 
181
- lookahead = lookahead.selection_with_alias(field_name)
182
- raise "Failed to look ahead the field: #{field_name}" if lookahead.is_a?(::GraphQL::Execution::Lookahead::NullLookahead)
192
+ lookahead = lookahead.selection_with_alias(field_name)
193
+ raise "Failed to look ahead the field: #{field_name}" if lookahead.is_a?(::GraphQL::Execution::Lookahead::NullLookahead)
183
194
 
184
- next lookahead.field.name if lookahead.arguments.empty?
195
+ next lookahead.field.name if lookahead.arguments.empty?
185
196
 
186
- args = lookahead.arguments.map { |_1, _2| "#{_1}:#{traverse_argument(_2)}" }.sort.join(",")
187
- "#{lookahead.field.name}(#{args})"
188
- }.join("/")
197
+ args = lookahead.arguments.map { |_1, _2| "#{_1}:#{traverse_argument(_2)}" }.sort.join(",")
198
+ "#{lookahead.field.name}(#{args})"
199
+ }.join("/")
200
+ end
189
201
  end
190
202
  end
191
203
 
@@ -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
- ].compact.join("/")
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,22 +176,28 @@ 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
175
- lookahead = query.lookahead
184
+ @path_cache_key ||= begin
185
+ @options.fetch(:path_cache_key) do
186
+ lookahead = query.lookahead
176
187
 
177
- path.map { |field_name|
178
- # Handle cached fields inside collections:
179
- next field_name if field_name.is_a?(Integer)
188
+ path.map { |field_name|
189
+ # Handle cached fields inside collections:
190
+ next field_name if field_name.is_a?(Integer)
180
191
 
181
- lookahead = lookahead.selection_with_alias(field_name)
182
- raise "Failed to look ahead the field: #{field_name}" if lookahead.is_a?(::GraphQL::Execution::Lookahead::NullLookahead)
192
+ lookahead = lookahead.selection_with_alias(field_name)
193
+ raise "Failed to look ahead the field: #{field_name}" if lookahead.is_a?(::GraphQL::Execution::Lookahead::NullLookahead)
183
194
 
184
- next lookahead.field.name if lookahead.arguments.empty?
195
+ next lookahead.field.name if lookahead.arguments.empty?
185
196
 
186
- args = lookahead.arguments.map { |_1, _2| "#{_1}:#{traverse_argument(_2)}" }.sort.join(",")
187
- "#{lookahead.field.name}(#{args})"
188
- }.join("/")
197
+ args = lookahead.arguments.map { |_1, _2| "#{_1}:#{traverse_argument(_2)}" }.sort.join(",")
198
+ "#{lookahead.field.name}(#{args})"
199
+ }.join("/")
200
+ end
189
201
  end
190
202
  end
191
203
 
@@ -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
- ].compact.join("/")
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,22 +176,28 @@ 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
175
- lookahead = query.lookahead
184
+ @path_cache_key ||= begin
185
+ @options.fetch(:path_cache_key) do
186
+ lookahead = query.lookahead
176
187
 
177
- path.map { |field_name|
178
- # Handle cached fields inside collections:
179
- next field_name if field_name.is_a?(Integer)
188
+ path.map { |field_name|
189
+ # Handle cached fields inside collections:
190
+ next field_name if field_name.is_a?(Integer)
180
191
 
181
- lookahead = lookahead.selection_with_alias(field_name)
182
- raise "Failed to look ahead the field: #{field_name}" if lookahead.is_a?(::GraphQL::Execution::Lookahead::NullLookahead)
192
+ lookahead = lookahead.selection_with_alias(field_name)
193
+ raise "Failed to look ahead the field: #{field_name}" if lookahead.is_a?(::GraphQL::Execution::Lookahead::NullLookahead)
183
194
 
184
- next lookahead.field.name if lookahead.arguments.empty?
195
+ next lookahead.field.name if lookahead.arguments.empty?
185
196
 
186
- args = lookahead.arguments.map { "#{_1}:#{traverse_argument(_2)}" }.sort.join(",")
187
- "#{lookahead.field.name}(#{args})"
188
- }.join("/")
197
+ args = lookahead.arguments.map { "#{_1}:#{traverse_argument(_2)}" }.sort.join(",")
198
+ "#{lookahead.field.name}(#{args})"
199
+ }.join("/")
200
+ end
189
201
  end
190
202
  end
191
203
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module GraphQL
4
4
  module FragmentCache
5
- VERSION = "1.16.0"
5
+ VERSION = "1.17.0"
6
6
  end
7
7
  end
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.16.0
4
+ version: 1.17.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-06 00:00:00.000000000 Z
11
+ date: 2022-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql