graphql-fragment_cache 1.19.0 → 1.20.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: d4dd3472ddcbe18e4c306b81770b5a9fa2dbe306968d1e16f2d98e81630bfec8
4
- data.tar.gz: 96c8cd920f0e46041c803527bbe3679841daa169aae82db6d627747eaf4632b9
3
+ metadata.gz: d8651322b53be7ad271913264155cb392c3ee945651806765f2a83545c3653dc
4
+ data.tar.gz: d80ec3c3e8cea7c27cb595582374e324c4b43571b3f459616d03036cc4411293
5
5
  SHA512:
6
- metadata.gz: c308ffcdfdb6fc7529ec3d094109cf7d21db8380b598435d6274e5b1f89a14110ece6fda565d9bc6429ae907066795597c8815f3e745c9a646033d246b2d1f2d
7
- data.tar.gz: 806ef15a72ca9eec45e4cde2e35ba43ceb29194c9ed23d77aa776bd3721a77f4d1b04ae8dc3d189e285be12a3cacd5dd1415faba7f57c745c55cb505eca6322e
6
+ metadata.gz: e846bc977828d95548c7e763a7eddb75de0e45a0d6cf950dc14973e10aae7df442fb31086874d06faecc01d16176abbb3e67f06a6c3082e53cea333b649d0685
7
+ data.tar.gz: 1fa660ff60d1d04b2750e15b0aca8c884a94f5c73e7a079584c2ba76272321c909af3fabb38badbe4d70c7280cc2e5cb2e4fbf70b917b69c0293c4dbbe2045ac
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 1.20.0 (2024-03-02)
6
+
7
+ - [PR#108](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/108) Use trace_with instead of deprecated instrument method ([@camero2734][])
8
+
5
9
  ## 1.19.0 (2023-11-03)
6
10
 
7
11
  - [PR#104](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/104) Support graphql-ruby 2.1.4 ([@DmitryTsepelev][])
@@ -181,3 +185,4 @@
181
185
  [@frostmark]: https://github.com/frostmark
182
186
  [@KTSCode]: https://github.com/KTSCode
183
187
  [@rince]: https://github.com/rince
188
+ [@camero2734]: https://github.com/camero2734
@@ -76,7 +76,7 @@ module GraphQL
76
76
  arguments = arguments.is_a?(::GraphQL::Execution::Interpreter::Arguments) ? arguments.keyword_arguments : arguments
77
77
  @ast_nodes.each do |ast_node|
78
78
  ast_node.selections.each do |selection|
79
- if GraphQL::FragmentCache.graphql_ruby_after_2_0_13?
79
+ if GraphQL::FragmentCache.graphql_ruby_after_2_0_13? && GraphQL::FragmentCache.graphql_ruby_before_2_1_4?
80
80
  find_selected_nodes(selection, next_field_defn, arguments: arguments, matches: next_nodes)
81
81
  else
82
82
  find_selected_nodes(selection, next_field_name, next_field_defn, arguments: arguments, matches: next_nodes)
@@ -212,7 +212,7 @@ module GraphQL
212
212
  end
213
213
 
214
214
  def object_key(obj)
215
- ((!obj.nil?) || nil) && obj._graphql_cache_key
215
+ ((((__safe_lvar__ = obj) || true) && (!__safe_lvar__.nil? || nil)) && __safe_lvar__._graphql_cache_key)
216
216
  end
217
217
  end
218
218
  end
@@ -33,13 +33,13 @@ module GraphQL
33
33
 
34
34
  def read(key)
35
35
  key = key.to_s
36
- ((!storage[key].nil?) || nil) && storage[key].then do |entry|
36
+ ((((__safe_lvar__ = storage[key]) || true) && (!__safe_lvar__.nil? || nil)) && __safe_lvar__.then { |entry|
37
37
  if entry.expired?
38
38
  delete(key)
39
39
  next
40
40
  end
41
41
  entry.value
42
- end
42
+ })
43
43
  end
44
44
 
45
45
  def write(key, value, options = {})
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GraphQL
4
+ module FragmentCache
5
+ using Ext
6
+
7
+ class WriteError < StandardError
8
+ attr_reader :key, :value, :original_error
9
+
10
+ def initialize(original_error, key, value)
11
+ @original_error = original_error
12
+ @key = key
13
+ @value = value
14
+
15
+ super(original_error.message)
16
+ end
17
+ end
18
+
19
+ class WriteMultiError < StandardError
20
+ attr_reader :values, :original_error
21
+
22
+ def initialize(original_error, values)
23
+ @original_error = original_error
24
+ @values = values
25
+
26
+ super(original_error.message)
27
+ end
28
+ end
29
+
30
+ # Saves resolved fragment values to cache store
31
+ module Cacher
32
+ class << self
33
+ def call(query)
34
+ return unless query.context.fragments?
35
+
36
+ if FragmentCache.cache_store.respond_to?(:write_multi)
37
+ batched_persist(query)
38
+ else
39
+ persist(query)
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def batched_persist(query)
46
+ select_valid_fragments(query).group_by(&:options).each do |options, group|
47
+ hash = group.map { |fragment| [fragment.cache_key, fragment.value] }.to_h
48
+
49
+ begin
50
+ FragmentCache.cache_store.write_multi(hash, options)
51
+ rescue => e
52
+ raise WriteMultiError.new(e, hash)
53
+ end
54
+ end
55
+ end
56
+
57
+ def persist(query)
58
+ select_valid_fragments(query).each do |fragment|
59
+ begin;FragmentCache.cache_store.write(fragment.cache_key, fragment.value, fragment.options)
60
+ rescue => e
61
+ raise WriteError.new(e, fragment.cache_key, fragment.value), e;end
62
+ end
63
+ end
64
+
65
+ def select_valid_fragments(query)
66
+ query.context.fragments.select(&:with_final_value?)
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -76,7 +76,7 @@ module GraphQL
76
76
  arguments = arguments.is_a?(::GraphQL::Execution::Interpreter::Arguments) ? arguments.keyword_arguments : arguments
77
77
  @ast_nodes.each do |ast_node|
78
78
  ast_node.selections.each do |selection|
79
- if GraphQL::FragmentCache.graphql_ruby_after_2_0_13?
79
+ if GraphQL::FragmentCache.graphql_ruby_after_2_0_13? && GraphQL::FragmentCache.graphql_ruby_before_2_1_4?
80
80
  find_selected_nodes(selection, next_field_defn, arguments: arguments, matches: next_nodes)
81
81
  else
82
82
  find_selected_nodes(selection, next_field_name, next_field_defn, arguments: arguments, matches: next_nodes)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module GraphQL
4
4
  module FragmentCache
5
- VERSION = "1.19.0"
5
+ VERSION = "1.20.0"
6
6
  end
7
7
  end
@@ -32,7 +32,14 @@ module GraphQL
32
32
  verify_interpreter_and_analysis!(schema_defn)
33
33
 
34
34
  schema_defn.tracer(Schema::Tracer)
35
- schema_defn.instrument(:query, Schema::Instrumentation)
35
+
36
+ if graphql_ruby_after_2_2_5?
37
+ schema_defn.trace_with(GraphQL::Tracing::LegacyHooksTrace)
38
+ schema_defn.instance_exec { own_instrumenters[:query] << Schema::Instrumentation }
39
+ else
40
+ schema_defn.instrument(:query, Schema::Instrumentation)
41
+ end
42
+
36
43
  schema_defn.extend(Schema::Patch)
37
44
  schema_defn.lazy_resolve(Schema::LazyCacheResolver, :resolve)
38
45
 
@@ -69,6 +76,10 @@ module GraphQL
69
76
  check_graphql_version "< 2.1.4"
70
77
  end
71
78
 
79
+ def graphql_ruby_after_2_2_5?
80
+ check_graphql_version "> 2.2.5"
81
+ end
82
+
72
83
  private
73
84
 
74
85
  def check_graphql_version(predicate)
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.19.0
4
+ version: 1.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - DmitryTsepelev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-03 00:00:00.000000000 Z
11
+ date: 2024-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.10.0
33
+ version: 0.15.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 0.10.0
40
+ version: 0.15.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: combustion
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -142,14 +142,14 @@ dependencies:
142
142
  requirements:
143
143
  - - '='
144
144
  - !ruby/object:Gem::Version
145
- version: 0.4.9
145
+ version: 0.6.0
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - '='
151
151
  - !ruby/object:Gem::Version
152
- version: 0.4.9
152
+ version: 0.6.0
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: graphql-batch
155
155
  requirement: !ruby/object:Gem::Requirement
@@ -168,16 +168,16 @@ dependencies:
168
168
  name: parser
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
- - - '='
171
+ - - ">="
172
172
  - !ruby/object:Gem::Version
173
- version: 3.1.2.1
173
+ version: '0'
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.1.2.1
180
+ version: '0'
181
181
  description: Fragment cache for graphql-ruby
182
182
  email:
183
183
  - dmitry.a.tsepelev@gmail.com
@@ -192,6 +192,7 @@ files:
192
192
  - bin/setup
193
193
  - lib/.rbnext/2.3/graphql/fragment_cache/cache_key_builder.rb
194
194
  - lib/.rbnext/2.3/graphql/fragment_cache/memory_store.rb
195
+ - lib/.rbnext/2.5/graphql/fragment_cache/cacher.rb
195
196
  - lib/.rbnext/2.7/graphql/fragment_cache/cache_key_builder.rb
196
197
  - lib/.rbnext/2.7/graphql/fragment_cache/ext/graphql_cache_key.rb
197
198
  - lib/graphql-fragment_cache.rb
@@ -228,7 +229,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
228
229
  requirements:
229
230
  - - ">="
230
231
  - !ruby/object:Gem::Version
231
- version: '2.6'
232
+ version: '3.0'
232
233
  required_rubygems_version: !ruby/object:Gem::Requirement
233
234
  requirements:
234
235
  - - ">="