Skip to content

Commit e10c427

Browse files
authored
Merge pull request #4107 from rmosolgo/2.0.9-handle-array-prev_type
Fix #add_type for duplicate types with cyclical references
2 parents 6736d3e + 4d9d797 commit e10c427

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/graphql/schema/addition.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def add_type(type, owner:, late_types:, path:)
151151
um << owner
152152
end
153153

154-
if (prev_type = get_local_type(type.graphql_name)) && prev_type == type
154+
if (prev_type = get_local_type(type.graphql_name)) && (prev_type == type || (prev_type.is_a?(Array) && prev_type.include?(type)))
155155
# No need to re-visit
156156
elsif type.is_a?(Class) && type < GraphQL::Schema::Directive
157157
@directives << type
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
require "spec_helper"
3+
4+
describe GraphQL::Schema::Addition do
5+
it "handles duplicate types with cycles" do
6+
duplicate_types_schema = Class.new(GraphQL::Schema)
7+
duplicate_types = 2.times.map {
8+
Class.new(GraphQL::Schema::Object) do
9+
graphql_name "Thing"
10+
field :thing, self
11+
end
12+
}
13+
duplicate_types_schema.orphan_types(duplicate_types)
14+
assert_equal 2, duplicate_types_schema.send(:own_types)["Thing"].size
15+
end
16+
end

0 commit comments

Comments
 (0)