Skip to content

Commit 82d6dd7

Browse files
author
Robert Mosolgo
authored
Merge pull request #3470 from rmosolgo/fix-connections-in-from-introspection
Don't decorate connections when loading from introspection responses
2 parents e81135e + c62ea1c commit 82d6dd7

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/graphql/schema/loader.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,21 @@ def define_directive(directive, type_resolver)
169169
def build_fields(type_defn, fields, type_resolver)
170170
loader = self
171171
fields.each do |field_hash|
172+
unwrapped_field_hash = field_hash
173+
while (of_type = unwrapped_field_hash["ofType"])
174+
unwrapped_field_hash = of_type
175+
end
176+
type_name = unwrapped_field_hash["name"]
177+
172178
type_defn.field(
173179
field_hash["name"],
174180
type: type_resolver.call(field_hash["type"]),
175181
description: field_hash["description"],
176182
deprecation_reason: field_hash["deprecationReason"],
177183
null: true,
178184
camelize: false,
185+
connection_extension: nil,
186+
connection: type_name.end_with?("Connection"),
179187
) do
180188
if field_hash["args"].any?
181189
loader.build_arguments(self, field_hash["args"], type_resolver)

spec/integration/rails/graphql/schema_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,16 @@
190190

191191
describe ".from_introspection" do
192192
let(:schema) {
193+
# This type would easily be mistaken for a connection... but it's not one.
194+
db_connection = Class.new(GraphQL::Schema::Object) do
195+
graphql_name "DatabaseConnection"
196+
field :name, String, null: false
197+
end
193198

194199
query_root = Class.new(GraphQL::Schema::Object) do
195200
graphql_name 'Query'
196201
field :str, String, null: true
202+
field :db, db_connection, null: false, connection: false
197203
end
198204

199205
Class.new(GraphQL::Schema) do

0 commit comments

Comments
 (0)