Skip to content

Commit 21b4409

Browse files
authored
Merge pull request #5468 from rmosolgo/fix-printer-interface-error
Don't modify cached array from types.interfaces
2 parents 68e7a6a + 4f0c24b commit 21b4409

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lib/graphql/language/document_from_schema_definition.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ def build_schema_node
5252

5353
def build_object_type_node(object_type)
5454
ints = @types.interfaces(object_type)
55+
5556
if !ints.empty?
56-
ints.sort_by!(&:graphql_name)
57+
ints = ints.sort_by(&:graphql_name)
5758
ints.map! { |iface| build_type_name_node(iface) }
5859
end
5960

spec/graphql/schema/printer_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,4 +1006,34 @@ class OddlyNamedQuery < GraphQL::Schema::Object
10061006
assert_equal expected_defn, Class.new(GraphQL::Schema) { extra_types(union_type, obj_1, obj_2) }.to_definition
10071007
end
10081008
end
1009+
1010+
it "works with interfaces and @oneOf directive" do
1011+
class SomeInputObject < GraphQL::Schema::InputObject
1012+
one_of
1013+
argument :a, Integer, required: false
1014+
argument :b, String, required: false
1015+
end
1016+
1017+
module SomeInterface
1018+
include GraphQL::Schema::Interface
1019+
field :id, ID
1020+
end
1021+
1022+
class SomeObject < GraphQL::Schema::Object
1023+
implements SomeInterface
1024+
field :some_field, Boolean do
1025+
argument :input, SomeInputObject
1026+
end
1027+
end
1028+
1029+
class SomeQueryType < GraphQL::Schema::Object
1030+
field :some_object, SomeObject, method: :some_object
1031+
end
1032+
1033+
class SomeSchema < GraphQL::Schema
1034+
query SomeQueryType
1035+
end
1036+
1037+
GraphQL::Schema::Printer.new(SomeSchema).print_type(SomeObject)
1038+
end
10091039
end

0 commit comments

Comments
 (0)