Skip to content

Commit f2abadc

Browse files
Allow graphql-ruby >= 2.1.4
1 parent f187b92 commit f2abadc

11 files changed

+2
-159
lines changed

.github/workflows/rspec.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ jobs:
2121
matrix:
2222
ruby: [3.1, 3.2, 3.3]
2323
gemfile: [
24-
"gemfiles/graphql_2_0_0.gemfile",
25-
"gemfiles/graphql_2_0_14.gemfile",
26-
"gemfiles/graphql_2_1_0.gemfile",
2724
"gemfiles/graphql_2_1_4.gemfile",
2825
"gemfiles/graphql_2_3_0.gemfile",
2926
"gemfiles/graphql_2_3_11.gemfile",

gemfiles/graphql_2_0_0.gemfile

Lines changed: 0 additions & 5 deletions
This file was deleted.

gemfiles/graphql_2_0_14.gemfile

Lines changed: 0 additions & 5 deletions
This file was deleted.

gemfiles/graphql_2_1_0.gemfile

Lines changed: 0 additions & 5 deletions
This file was deleted.

graphql-ruby-fragment_cache.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ Gem::Specification.new do |spec|
2020
spec.files = Dir.glob("lib/**/*") + Dir.glob("lib/.rbnext/**/*") + Dir.glob("bin/**/*") + %w[README.md LICENSE.txt CHANGELOG.md]
2121
spec.require_paths = ["lib"]
2222

23-
spec.required_ruby_version = ">= 3.0"
23+
spec.required_ruby_version = ">= 3.1"
2424

25-
spec.add_dependency "graphql", ">= 2.0.0"
25+
spec.add_dependency "graphql", ">= 2.1.4"
2626

2727
# When gem is installed from source, we add `ruby-next` as a dependency
2828
# to auto-transpile source files during the first load

lib/graphql/fragment_cache.rb

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ class << self
3232
attr_accessor :skip_cache_when_query_has_errors
3333

3434
def use(schema_defn, options = {})
35-
verify_interpreter_and_analysis!(schema_defn)
36-
3735
if GraphRubyVersion.after_2_2_5?
3836
schema_defn.trace_with(Schema::Instrumentation::Tracer)
3937
else
@@ -70,20 +68,6 @@ def cache_store=(store)
7068
def check_graphql_version(predicate)
7169
Gem::Dependency.new("graphql", predicate).match?("graphql", GraphQL::VERSION)
7270
end
73-
74-
def verify_interpreter_and_analysis!(schema_defn)
75-
if GraphRubyVersion.before_2_0?
76-
unless schema_defn.interpreter?
77-
raise StandardError,
78-
"GraphQL::Execution::Interpreter should be enabled for fragment caching"
79-
end
80-
81-
unless schema_defn.analysis_engine == GraphQL::Analysis::AST
82-
raise StandardError,
83-
"GraphQL::Analysis::AST should be enabled for fragment caching"
84-
end
85-
end
86-
end
8771
end
8872

8973
self.cache_store = MemoryStore.new

lib/graphql/fragment_cache/cache_key_builder.rb

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -52,69 +52,6 @@ def selection_with_alias(name, **kwargs)
5252
return selection(name, **kwargs) if selects?(name, **kwargs)
5353
alias_selection(name, **kwargs)
5454
end
55-
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)
59-
60-
alias_node = lookup_alias_node(ast_nodes, name)
61-
return ::GraphQL::Execution::Lookahead::NULL_LOOKAHEAD unless alias_node
62-
63-
next_field_name = alias_node.name
64-
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
72-
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
85-
end
86-
end
87-
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
93-
else
94-
::GraphQL::Execution::Lookahead::NULL_LOOKAHEAD
95-
end
96-
end
97-
98-
def alias_selections
99-
return @alias_selections if defined?(@alias_selections)
100-
@alias_selections ||= {}
101-
end
102-
103-
def lookup_alias_node(nodes, name)
104-
return if nodes.empty?
105-
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
111-
112-
return node if node.alias?(name)
113-
child = lookup_alias_node(node.children, name)
114-
return child if child
115-
end
116-
end
117-
end
11855
end
11956
})
12057

lib/graphql/fragment_cache/graphql_ruby_version.rb

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,6 @@ module FragmentCache
77
module GraphRubyVersion
88
module_function
99

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-
2210
def after_2_2_5?
2311
check_graphql_version "> 2.2.5"
2412
end

spec/graphql/fragment_cache_spec.rb

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,6 @@
33
require "spec_helper"
44

55
describe GraphQL::FragmentCache do
6-
describe ".use" do
7-
if GraphQL::FragmentCache::GraphRubyVersion.before_2_0?
8-
it "raises if interpreter is not used" do
9-
expect {
10-
Class.new(GraphQL::Schema) {
11-
use GraphQL::Execution::Execute
12-
use GraphQL::FragmentCache
13-
}
14-
}.to raise_error(
15-
StandardError, "GraphQL::Execution::Interpreter should be enabled for fragment caching"
16-
)
17-
end
18-
19-
it "raise if interpreter is used without AST" do
20-
expect {
21-
Class.new(GraphQL::Schema) do
22-
use GraphQL::Analysis
23-
use GraphQL::FragmentCache
24-
end
25-
}.to raise_error(
26-
StandardError, "GraphQL::Analysis::AST should be enabled for fragment caching"
27-
)
28-
end
29-
30-
it "doesn't raise if interpreter is used with AST" do
31-
expect {
32-
Class.new(GraphQL::Schema) do
33-
use GraphQL::FragmentCache
34-
end
35-
}.not_to raise_error
36-
end
37-
end
38-
end
39-
406
describe ".cache_store=" do
417
around do |ex|
428
old_store = described_class.cache_store

spec/support/schema_helper.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@
33
module SchemaHelper
44
def build_schema(&block)
55
Class.new(GraphQL::Schema) do
6-
if GraphQL::FragmentCache::GraphRubyVersion.before_2_0?
7-
use GraphQL::Execution::Interpreter
8-
use GraphQL::Analysis::AST
9-
10-
use GraphQL::Pagination::Connections
11-
end
12-
136
use GraphQL::FragmentCache
147

158
instance_eval(&block)

spec/support/test_schema.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,6 @@ def cached_post_by_complex_input(complex_post_input:)
116116
end
117117

118118
class TestSchema < GraphQL::Schema
119-
if GraphQL::FragmentCache::GraphRubyVersion.before_2_0?
120-
use GraphQL::Execution::Interpreter
121-
use GraphQL::Analysis::AST
122-
123-
use GraphQL::Pagination::Connections
124-
end
125-
126119
use GraphQL::Batch
127120
use GraphQL::FragmentCache
128121

0 commit comments

Comments
 (0)