Skip to content

Commit

Permalink
Merge pull request #4107 from rmosolgo/2.0.9-handle-array-prev_type
Browse files Browse the repository at this point in the history
Fix #add_type for duplicate types with cyclical references
  • Loading branch information
rmosolgo committed Jun 20, 2022
2 parents 6736d3e + 4d9d797 commit e10c427
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/graphql/schema/addition.rb
Expand Up @@ -151,7 +151,7 @@ def add_type(type, owner:, late_types:, path:)
um << owner
end

if (prev_type = get_local_type(type.graphql_name)) && prev_type == type
if (prev_type = get_local_type(type.graphql_name)) && (prev_type == type || (prev_type.is_a?(Array) && prev_type.include?(type)))
# No need to re-visit
elsif type.is_a?(Class) && type < GraphQL::Schema::Directive
@directives << type
Expand Down
16 changes: 16 additions & 0 deletions spec/graphql/schema/addition_spec.rb
@@ -0,0 +1,16 @@
# frozen_string_literal: true
require "spec_helper"

describe GraphQL::Schema::Addition do
it "handles duplicate types with cycles" do
duplicate_types_schema = Class.new(GraphQL::Schema)
duplicate_types = 2.times.map {
Class.new(GraphQL::Schema::Object) do
graphql_name "Thing"
field :thing, self
end
}
duplicate_types_schema.orphan_types(duplicate_types)
assert_equal 2, duplicate_types_schema.send(:own_types)["Thing"].size
end
end

0 comments on commit e10c427

Please sign in to comment.