graphql-fragment_cache 1.17.0 → 1.18.1

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: e2c544bc2742643748c5e36c59b3414def73c22e6f7c4b5080504751ea564ecd
4
- data.tar.gz: b61980525863502ea4f30eeb96fee11dbc11a906ab98b863ed0ece7f9d97d1e9
3
+ metadata.gz: da685d54588830a63cc96b79d9348f496c3d9e114b8bbd39353d89bbf734a2be
4
+ data.tar.gz: e97d85a3bb1b1ef33b50f9b784f14d5cf0662a220cb46b3e0195422775ca230a
5
5
  SHA512:
6
- metadata.gz: aac16bb6d2541e573796043ebf2da2ffa171918730ad95f4613db1f6b20cb1156a4a1cb3d70b7e0c39be57a6d56d2cfd3a27d95470c0c316f8f95a756bf83377
7
- data.tar.gz: 85349b218d754a716db3aa8165e8de64a92b48c22e4b4b1615e612d041000701a090c643fa6b6e68326bb51a3688df2eb71f84604a1bfd19034eb01201453b26
6
+ metadata.gz: 435e71e009c537926c19b2089815b8633a91f0f30caf49fbc45c71d227ff9923867a52c01ed9a0e0e8eff4c51bfa7887371af5ce51281c74bc0be7fcd9566f82
7
+ data.tar.gz: 87eadfeba581e7ad08a492ae9c82c6a40406def445b1284943dfa55c320426d7135401761561e3fd7ad1c7c99a987b0a52ec1fc6c5c3a229b8ce5ee5a77e3bc6
data/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 1.18.1 (2023-01-06)
6
+
7
+ - [PR#96](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/96) Properly pass arguments to `write_multi` ([@DmitryTsepelev][])
8
+
9
+ ## 1.18.0 (2022-12-28)
10
+
11
+ - [PR#94](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/94) Ruby 3 support ([@DmitryTsepelev][])
12
+
5
13
  ## 1.17.0 (2022-11-09)
6
14
 
7
15
  - [PR#92](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/92) Make cache keys human-readable ([@jeromedalbert][])
@@ -128,7 +128,7 @@ module GraphQL
128
128
 
129
129
  attr_reader :query, :path, :object, :schema
130
130
 
131
- def initialize(object: nil, query:, path:, **options)
131
+ def initialize(query:, path:, object: nil, **options)
132
132
  @object = object
133
133
  @query = query
134
134
  @schema = query.schema
@@ -181,23 +181,21 @@ module GraphQL
181
181
  end
182
182
 
183
183
  def path_cache_key
184
- @path_cache_key ||= begin
185
- @options.fetch(:path_cache_key) do
186
- lookahead = query.lookahead
184
+ @path_cache_key ||= @options.fetch(:path_cache_key) do
185
+ lookahead = query.lookahead
187
186
 
188
- path.map { |field_name|
189
- # Handle cached fields inside collections:
190
- next field_name if field_name.is_a?(Integer)
187
+ path.map { |field_name|
188
+ # Handle cached fields inside collections:
189
+ next field_name if field_name.is_a?(Integer)
191
190
 
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)
191
+ lookahead = lookahead.selection_with_alias(field_name)
192
+ raise "Failed to look ahead the field: #{field_name}" if lookahead.is_a?(::GraphQL::Execution::Lookahead::NullLookahead)
194
193
 
195
- next lookahead.field.name if lookahead.arguments.empty?
194
+ next lookahead.field.name if lookahead.arguments.empty?
196
195
 
197
- args = lookahead.arguments.map { |_1, _2| "#{_1}:#{traverse_argument(_2)}" }.sort.join(",")
198
- "#{lookahead.field.name}(#{args})"
199
- }.join("/")
200
- end
196
+ args = lookahead.arguments.map { |_1, _2| "#{_1}:#{traverse_argument(_2)}" }.sort.join(",")
197
+ "#{lookahead.field.name}(#{args})"
198
+ }.join("/")
201
199
  end
202
200
  end
203
201
 
@@ -42,7 +42,8 @@ module GraphQL
42
42
  end
43
43
  end
44
44
 
45
- def write(key, value, expires_in: default_expires_in, **options)
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, query:, path:, **options)
131
+ def initialize(query:, path:, object: nil, **options)
132
132
  @object = object
133
133
  @query = query
134
134
  @schema = query.schema
@@ -181,23 +181,21 @@ module GraphQL
181
181
  end
182
182
 
183
183
  def path_cache_key
184
- @path_cache_key ||= begin
185
- @options.fetch(:path_cache_key) do
186
- lookahead = query.lookahead
184
+ @path_cache_key ||= @options.fetch(:path_cache_key) do
185
+ lookahead = query.lookahead
187
186
 
188
- path.map { |field_name|
189
- # Handle cached fields inside collections:
190
- next field_name if field_name.is_a?(Integer)
187
+ path.map { |field_name|
188
+ # Handle cached fields inside collections:
189
+ next field_name if field_name.is_a?(Integer)
191
190
 
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)
191
+ lookahead = lookahead.selection_with_alias(field_name)
192
+ raise "Failed to look ahead the field: #{field_name}" if lookahead.is_a?(::GraphQL::Execution::Lookahead::NullLookahead)
194
193
 
195
- next lookahead.field.name if lookahead.arguments.empty?
194
+ next lookahead.field.name if lookahead.arguments.empty?
196
195
 
197
- args = lookahead.arguments.map { |_1, _2| "#{_1}:#{traverse_argument(_2)}" }.sort.join(",")
198
- "#{lookahead.field.name}(#{args})"
199
- }.join("/")
200
- end
196
+ args = lookahead.arguments.map { |_1, _2| "#{_1}:#{traverse_argument(_2)}" }.sort.join(",")
197
+ "#{lookahead.field.name}(#{args})"
198
+ }.join("/")
201
199
  end
202
200
  end
203
201
 
@@ -128,7 +128,7 @@ module GraphQL
128
128
 
129
129
  attr_reader :query, :path, :object, :schema
130
130
 
131
- def initialize(object: nil, query:, path:, **options)
131
+ def initialize(query:, path:, object: nil, **options)
132
132
  @object = object
133
133
  @query = query
134
134
  @schema = query.schema
@@ -181,23 +181,21 @@ module GraphQL
181
181
  end
182
182
 
183
183
  def path_cache_key
184
- @path_cache_key ||= begin
185
- @options.fetch(:path_cache_key) do
186
- lookahead = query.lookahead
184
+ @path_cache_key ||= @options.fetch(:path_cache_key) do
185
+ lookahead = query.lookahead
187
186
 
188
- path.map { |field_name|
189
- # Handle cached fields inside collections:
190
- next field_name if field_name.is_a?(Integer)
187
+ path.map { |field_name|
188
+ # Handle cached fields inside collections:
189
+ next field_name if field_name.is_a?(Integer)
191
190
 
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)
191
+ lookahead = lookahead.selection_with_alias(field_name)
192
+ raise "Failed to look ahead the field: #{field_name}" if lookahead.is_a?(::GraphQL::Execution::Lookahead::NullLookahead)
194
193
 
195
- next lookahead.field.name if lookahead.arguments.empty?
194
+ next lookahead.field.name if lookahead.arguments.empty?
196
195
 
197
- args = lookahead.arguments.map { "#{_1}:#{traverse_argument(_2)}" }.sort.join(",")
198
- "#{lookahead.field.name}(#{args})"
199
- }.join("/")
200
- end
196
+ args = lookahead.arguments.map { "#{_1}:#{traverse_argument(_2)}" }.sort.join(",")
197
+ "#{lookahead.field.name}(#{args})"
198
+ }.join("/")
201
199
  end
202
200
  end
203
201
 
@@ -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, **options)
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, **fragment.options)
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, expires_in: default_expires_in, **options)
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 block_given? || object_to_cache != NO_OBJECT
27
+ raise ArgumentError, "Block or argument must be provided" unless block || object_to_cache != NO_OBJECT
28
28
  unless GraphQL::FragmentCache.enabled
29
- return block_given? ? block.call : object_to_cache
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 block_given? ? block.call : object_to_cache
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|
@@ -2,6 +2,6 @@
2
2
 
3
3
  module GraphQL
4
4
  module FragmentCache
5
- VERSION = "1.17.0"
5
+ VERSION = "1.18.1"
6
6
  end
7
7
  end
@@ -55,7 +55,7 @@ module GraphQL
55
55
  @cache_store = store
56
56
  end
57
57
 
58
- alias skip_cache_when_query_has_errors? skip_cache_when_query_has_errors
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.17.0
4
+ version: 1.18.1
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-09 00:00:00.000000000 Z
11
+ date: 2023-01-05 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.0.2.0
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.0.2.0
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.2.33
238
+ rubygems_version: 3.4.1
239
239
  signing_key:
240
240
  specification_version: 4
241
241
  summary: Fragment cache for graphql-ruby