diff --git a/lib/graphql/schema/addition.rb b/lib/graphql/schema/addition.rb index 35b98e6c4a..e378f729a0 100644 --- a/lib/graphql/schema/addition.rb +++ b/lib/graphql/schema/addition.rb @@ -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 diff --git a/spec/graphql/schema/addition_spec.rb b/spec/graphql/schema/addition_spec.rb new file mode 100644 index 0000000000..62c54930f9 --- /dev/null +++ b/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