graphql-fragment_cache 1.19.0 → 1.20.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/lib/.rbnext/2.3/graphql/fragment_cache/cache_key_builder.rb +2 -2
- data/lib/.rbnext/2.3/graphql/fragment_cache/memory_store.rb +2 -2
- data/lib/.rbnext/2.5/graphql/fragment_cache/cacher.rb +71 -0
- data/lib/.rbnext/2.7/graphql/fragment_cache/cache_key_builder.rb +1 -1
- data/lib/graphql/fragment_cache/cache_key_builder.rb +46 -44
- data/lib/graphql/fragment_cache/graphql_ruby_version.rb +31 -0
- data/lib/graphql/fragment_cache/version.rb +1 -1
- data/lib/graphql/fragment_cache.rb +11 -15
- metadata +13 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1290ae93c3ed819164a80214348eb8539ca1f502d66494c78b67a70442cc377f
|
4
|
+
data.tar.gz: 90bab17ae895c6164ae77da598d7afa3073ca0e0cb6b6f21f848fc4038d71a89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae23bb92581ad0a5527516675ea08ad1668ea98dc6bf63e85411576f5e1321a5db679c0fe24111abdd1db8629577d67bfc5f2223f9cca69c7c94ca3f57cd779a
|
7
|
+
data.tar.gz: 07b1772b1862c3a7905894321b17ddf8b3beec3520565e654530b185d269746f8f94c3fa397fa9707bf41afbcb51cc5d6332b81fd2f571d492aab1d05c66529b
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,15 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
+
## 1.20.1 (2024-04-03)
|
6
|
+
|
7
|
+
- [PR#112](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/112) fix tracer deprecation warnings ([@diegofigueroa][])
|
8
|
+
- [PR#109](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/109) Remove `Lookahead` patch in modern versions of graphql-ruby ([@DmitryTsepelev][])
|
9
|
+
|
10
|
+
## 1.20.0 (2024-03-02)
|
11
|
+
|
12
|
+
- [PR#108](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/108) Use trace_with instead of deprecated instrument method ([@camero2734][])
|
13
|
+
|
5
14
|
## 1.19.0 (2023-11-03)
|
6
15
|
|
7
16
|
- [PR#104](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/104) Support graphql-ruby 2.1.4 ([@DmitryTsepelev][])
|
@@ -181,3 +190,5 @@
|
|
181
190
|
[@frostmark]: https://github.com/frostmark
|
182
191
|
[@KTSCode]: https://github.com/KTSCode
|
183
192
|
[@rince]: https://github.com/rince
|
193
|
+
[@camero2734]: https://github.com/camero2734
|
194
|
+
[@diegofigueroa]: https://github.com/diegofigueroa
|
@@ -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
|
-
((!
|
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
|
-
((
|
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
|
-
|
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)
|
@@ -53,64 +53,66 @@ module GraphQL
|
|
53
53
|
alias_selection(name, **kwargs)
|
54
54
|
end
|
55
55
|
|
56
|
-
|
57
|
-
|
56
|
+
if GraphRubyVersion.before_2_1_4?
|
57
|
+
def alias_selection(name, selected_type: @selected_type, arguments: nil)
|
58
|
+
return alias_selections[name] if alias_selections.key?(name)
|
58
59
|
|
59
|
-
|
60
|
-
|
60
|
+
alias_node = lookup_alias_node(ast_nodes, name)
|
61
|
+
return ::GraphQL::Execution::Lookahead::NULL_LOOKAHEAD unless alias_node
|
61
62
|
|
62
|
-
|
63
|
+
next_field_name = alias_node.name
|
63
64
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
65
|
+
# From https://github.com/rmosolgo/graphql-ruby/blob/1a9a20f3da629e63ea8e5ee8400be82218f9edc3/lib/graphql/execution/lookahead.rb#L91
|
66
|
+
next_field_defn =
|
67
|
+
if GraphRubyVersion.before_2_0?
|
68
|
+
get_class_based_field(selected_type, next_field_name)
|
69
|
+
else
|
70
|
+
@query.get_field(selected_type, next_field_name)
|
71
|
+
end
|
71
72
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
73
|
+
alias_selections[name] =
|
74
|
+
if next_field_defn
|
75
|
+
next_nodes = []
|
76
|
+
arguments = @query.arguments_for(alias_node, next_field_defn)
|
77
|
+
arguments = arguments.is_a?(::GraphQL::Execution::Interpreter::Arguments) ? arguments.keyword_arguments : arguments
|
78
|
+
@ast_nodes.each do |ast_node|
|
79
|
+
ast_node.selections.each do |selection|
|
80
|
+
if GraphRubyVersion.after_2_0_13? && GraphRubyVersion.before_2_1_4?
|
81
|
+
find_selected_nodes(selection, next_field_defn, arguments: arguments, matches: next_nodes)
|
82
|
+
else
|
83
|
+
find_selected_nodes(selection, next_field_name, next_field_defn, arguments: arguments, matches: next_nodes)
|
84
|
+
end
|
83
85
|
end
|
84
86
|
end
|
85
|
-
end
|
86
87
|
|
87
|
-
|
88
|
-
|
88
|
+
if next_nodes.any?
|
89
|
+
::GraphQL::Execution::Lookahead.new(query: @query, ast_nodes: next_nodes, field: next_field_defn, owner_type: selected_type)
|
90
|
+
else
|
91
|
+
::GraphQL::Execution::Lookahead::NULL_LOOKAHEAD
|
92
|
+
end
|
89
93
|
else
|
90
94
|
::GraphQL::Execution::Lookahead::NULL_LOOKAHEAD
|
91
95
|
end
|
92
|
-
|
93
|
-
::GraphQL::Execution::Lookahead::NULL_LOOKAHEAD
|
94
|
-
end
|
95
|
-
end
|
96
|
+
end
|
96
97
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
98
|
+
def alias_selections
|
99
|
+
return @alias_selections if defined?(@alias_selections)
|
100
|
+
@alias_selections ||= {}
|
101
|
+
end
|
101
102
|
|
102
|
-
|
103
|
-
|
103
|
+
def lookup_alias_node(nodes, name)
|
104
|
+
return if nodes.empty?
|
104
105
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
106
|
+
nodes.find do |node|
|
107
|
+
if node.is_a?(GraphQL::Language::Nodes::FragmentSpread)
|
108
|
+
node = @query.fragments[node.name]
|
109
|
+
raise("Invariant: Can't look ahead to nonexistent fragment #{node.name} (found: #{@query.fragments.keys})") unless node
|
110
|
+
end
|
110
111
|
|
111
|
-
|
112
|
-
|
113
|
-
|
112
|
+
return node if node.alias?(name)
|
113
|
+
child = lookup_alias_node(node.children, name)
|
114
|
+
return child if child
|
115
|
+
end
|
114
116
|
end
|
115
117
|
end
|
116
118
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
using RubyNext
|
4
|
+
|
5
|
+
module GraphQL
|
6
|
+
module FragmentCache
|
7
|
+
module GraphRubyVersion
|
8
|
+
module_function
|
9
|
+
|
10
|
+
def before_2_0?
|
11
|
+
check_graphql_version "< 2.0.0"
|
12
|
+
end
|
13
|
+
|
14
|
+
def after_2_0_13?
|
15
|
+
check_graphql_version "> 2.0.13"
|
16
|
+
end
|
17
|
+
|
18
|
+
def before_2_1_4?
|
19
|
+
check_graphql_version "< 2.1.4"
|
20
|
+
end
|
21
|
+
|
22
|
+
def after_2_2_5?
|
23
|
+
check_graphql_version "> 2.2.5"
|
24
|
+
end
|
25
|
+
|
26
|
+
def check_graphql_version(predicate)
|
27
|
+
Gem::Dependency.new("graphql", predicate).match?("graphql", GraphQL::VERSION)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
require "graphql"
|
4
4
|
|
5
|
+
require "graphql/fragment_cache/graphql_ruby_version"
|
6
|
+
|
5
7
|
require "graphql/fragment_cache/ext/context_fragments"
|
6
8
|
require "graphql/fragment_cache/ext/graphql_cache_key"
|
7
9
|
require "graphql/fragment_cache/object"
|
@@ -31,8 +33,14 @@ module GraphQL
|
|
31
33
|
def use(schema_defn, options = {})
|
32
34
|
verify_interpreter_and_analysis!(schema_defn)
|
33
35
|
|
34
|
-
|
35
|
-
|
36
|
+
if GraphRubyVersion.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.tracer(Schema::Tracer)
|
41
|
+
schema_defn.instrument(:query, Schema::Instrumentation)
|
42
|
+
end
|
43
|
+
|
36
44
|
schema_defn.extend(Schema::Patch)
|
37
45
|
schema_defn.lazy_resolve(Schema::LazyCacheResolver, :resolve)
|
38
46
|
|
@@ -57,18 +65,6 @@ module GraphQL
|
|
57
65
|
|
58
66
|
alias_method :skip_cache_when_query_has_errors?, :skip_cache_when_query_has_errors
|
59
67
|
|
60
|
-
def graphql_ruby_before_2_0?
|
61
|
-
check_graphql_version "< 2.0.0"
|
62
|
-
end
|
63
|
-
|
64
|
-
def graphql_ruby_after_2_0_13?
|
65
|
-
check_graphql_version "> 2.0.13"
|
66
|
-
end
|
67
|
-
|
68
|
-
def graphql_ruby_before_2_1_4?
|
69
|
-
check_graphql_version "< 2.1.4"
|
70
|
-
end
|
71
|
-
|
72
68
|
private
|
73
69
|
|
74
70
|
def check_graphql_version(predicate)
|
@@ -76,7 +72,7 @@ module GraphQL
|
|
76
72
|
end
|
77
73
|
|
78
74
|
def verify_interpreter_and_analysis!(schema_defn)
|
79
|
-
if
|
75
|
+
if GraphRubyVersion.before_2_0?
|
80
76
|
unless schema_defn.interpreter?
|
81
77
|
raise StandardError,
|
82
78
|
"GraphQL::Execution::Interpreter should be enabled for fragment caching"
|
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.20.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DmitryTsepelev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-04-03 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.
|
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.
|
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.
|
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.
|
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:
|
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:
|
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
|
@@ -203,6 +204,7 @@ files:
|
|
203
204
|
- lib/graphql/fragment_cache/ext/graphql_cache_key.rb
|
204
205
|
- lib/graphql/fragment_cache/field_extension.rb
|
205
206
|
- lib/graphql/fragment_cache/fragment.rb
|
207
|
+
- lib/graphql/fragment_cache/graphql_ruby_version.rb
|
206
208
|
- lib/graphql/fragment_cache/memory_store.rb
|
207
209
|
- lib/graphql/fragment_cache/object.rb
|
208
210
|
- lib/graphql/fragment_cache/object_helpers.rb
|
@@ -228,7 +230,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
228
230
|
requirements:
|
229
231
|
- - ">="
|
230
232
|
- !ruby/object:Gem::Version
|
231
|
-
version: '
|
233
|
+
version: '3.0'
|
232
234
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
233
235
|
requirements:
|
234
236
|
- - ">="
|