Skip to content

Commit f5a75ce

Browse files
committed
Check if new connections before calling method on it
1 parent 862e8f3 commit f5a75ce

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/graphql/schema/field/connection_extension.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def after_resolve(value:, object:, arguments:, context:, memo:)
4444
if field.has_max_page_size? && !value.has_max_page_size_override?
4545
value.max_page_size = field.max_page_size
4646
end
47-
if (custom_t = context.schema.connections.edge_class_for_field(@field))
47+
if context.schema.new_connections? && (custom_t = context.schema.connections.edge_class_for_field(@field))
4848
value.edge_class = custom_t
4949
end
5050
value

spec/graphql/pagination/connections_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,23 @@ def things2
112112

113113
assert_includes err.message, "undefined method `no_such_method' for <BadThing!>"
114114
end
115+
116+
class SingleNewConnectionSchema < GraphQL::Schema
117+
class Query < GraphQL::Schema::Object
118+
field :strings, GraphQL::Types::String.connection_type, null: false
119+
120+
def strings
121+
GraphQL::Pagination::ArrayConnection.new(["a", "b", "c"])
122+
end
123+
end
124+
125+
query(Query)
126+
use GraphQL::Execution::Interpreter
127+
use GraphQL::Analysis::AST
128+
end
129+
130+
it "works when new connections are not installed" do
131+
res = SingleNewConnectionSchema.execute("{ strings(first: 2) { edges { node } } }")
132+
assert_equal ["a", "b"], res["data"]["strings"]["edges"].map { |e| e["node"] }
133+
end
115134
end

0 commit comments

Comments
 (0)