Skip to content

Commit 3459702

Browse files
author
Robert Mosolgo
authored
Merge pull request #3278 from lucianosousa/ruby-3-support
Add support to Ruby 3.0.0
2 parents f9d330c + e0e0c34 commit 3459702

File tree

5 files changed

+34
-8
lines changed

5 files changed

+34
-8
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ jobs:
4747
bundler: "1"
4848
# Rails 5.2 is tested with Postgresql below
4949
- gemfile: gemfiles/rails_6.0.gemfile
50-
ruby: 2.5
51-
- gemfile: gemfiles/rails_master.gemfile
5250
ruby: 2.7
51+
- gemfile: gemfiles/rails_master.gemfile
52+
ruby: 3.0
5353
runs-on: ubuntu-latest
5454
steps:
5555
- run: echo BUNDLE_GEMFILE=${{ matrix.gemfile }} > $GITHUB_ENV

lib/graphql/invalid_null_error.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def subclass_for(parent_class)
3939
end
4040

4141
def inspect
42-
if name.nil? && parent_class.respond_to?(:mutation) && (mutation = parent_class.mutation)
42+
if (name.nil? || parent_class.name.nil?) && parent_class.respond_to?(:mutation) && (mutation = parent_class.mutation)
4343
"#{mutation.inspect}::#{parent_class.graphql_name}::InvalidNullError"
4444
else
4545
super

lib/graphql/tracing/platform_tracing.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def trace_field(type, field)
9595
end
9696

9797
def self.use(schema_defn, options = {})
98-
tracer = self.new(options)
98+
tracer = self.new(**options)
9999
schema_defn.instrument(:field, tracer)
100100
schema_defn.tracer(tracer)
101101
end

spec/integration/rails/graphql/relay/connection_type_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
assert_equal [upcased_rebels_name] , bases["edges"].map { |e| e["upcasedParentName"] }.uniq
3636
end
3737
assert_equal ["Yavin", "Echo Base", "Secret Hideout"] , bases["edges"].map { |e| e["node"]["name"] }
38-
assert_equal ["StarWars::CustomBaseEdge"] , bases["edges"].map { |e| e["edgeClassName"] }.uniq
38+
assert_equal [TESTING_INTERPRETER ? "StarWars::NewCustomBaseEdge" : "StarWars::CustomBaseEdge"] , bases["edges"].map { |e| e["edgeClassName"] }.uniq
3939
end
4040
end
4141

spec/support/star_wars/schema.rb

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ def upcased_parent_name
6666
end
6767
end
6868

69+
class NewCustomBaseEdge < GraphQL::Pagination::Connection::Edge
70+
def upcased_name
71+
node.name.upcase
72+
end
73+
74+
def upcased_parent_name
75+
parent.name.upcase
76+
end
77+
end
78+
6979
class CustomBaseEdgeType < GraphQL::Types::Relay::BaseEdge
7080
node_type(BaseType)
7181
field :upcased_name, String, null: true
@@ -78,10 +88,16 @@ def edge_class_name
7888
end
7989

8090
class CustomEdgeBaseConnectionType < GraphQL::Types::Relay::BaseConnection
81-
edge_type(CustomBaseEdgeType, edge_class: CustomBaseEdge, nodes_field: true)
91+
edge_type(CustomBaseEdgeType, edge_class: (TESTING_INTERPRETER ? NewCustomBaseEdge : CustomBaseEdge), nodes_field: true)
8292
field :total_count_times_100, Integer, null: true
8393
def total_count_times_100
84-
object.nodes.count * 100
94+
if object.is_a?(GraphQL::Pagination::Connection)
95+
# new-style
96+
object.items.count * 100
97+
else
98+
# legacy
99+
object.nodes.count * 100
100+
end
85101
end
86102

87103
field :field_name, String, null: true
@@ -318,6 +334,16 @@ def edge_nodes
318334
end
319335
end
320336

337+
class NewLazyNodesRelationConnection < GraphQL::Pagination::ActiveRecordRelationConnection
338+
def initialize(wrapper, **kwargs)
339+
super(wrapper.relation, **kwargs)
340+
end
341+
342+
def edge_nodes
343+
LazyWrapper.new { super }
344+
end
345+
end
346+
321347
GraphQL::Relay::BaseConnection.register_connection_implementation(LazyNodesWrapper, LazyNodesRelationConnection)
322348

323349
class QueryType < GraphQL::Schema::Object
@@ -436,7 +462,7 @@ class Schema < GraphQL::Schema
436462
use GraphQL::Execution::Interpreter
437463
use GraphQL::Analysis::AST
438464
use GraphQL::Pagination::Connections
439-
connections.add(LazyNodesWrapper, LazyNodesRelationConnection)
465+
connections.add(LazyNodesWrapper, NewLazyNodesRelationConnection)
440466
end
441467

442468
def self.resolve_type(type, object, ctx)

0 commit comments

Comments
 (0)