File tree Expand file tree Collapse file tree
main/java/graphql/schema/idl
test/groovy/graphql/schema/idl Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -60,8 +60,12 @@ public TypeDefinitionRegistry merge(TypeDefinitionRegistry typeRegistry) throws
6060 throw new SchemaProblem (errors );
6161 }
6262
63+ if (this .schema == null ) {
64+ // ensure schema is not overwritten by merge
65+ this .schema = typeRegistry .schema ;
66+ }
67+
6368 // ok commit to the merge
64- this .schema = typeRegistry .schema ;
6569 this .types .putAll (tempTypes );
6670 this .typeExtensions .putAll (tempTypeExtensions );
6771 this .scalarTypes .putAll (tempScalarTypes );
Original file line number Diff line number Diff line change @@ -45,6 +45,29 @@ class TypeDefinitionRegistryTest extends Specification {
4545 }
4646
4747
48+ def " merging multiple type registries does not overwrite schema definition" () {
49+
50+ def spec1 = """
51+ schema {
52+ query: Query
53+ }
54+ """
55+
56+ def spec2 = """
57+ type Post { id: Int! }
58+ """
59+
60+ def result1 = compile(spec1)
61+ def result2 = compile(spec2)
62+
63+ def registry = result1. merge(result2)
64+
65+ expect :
66+ result1. schemaDefinition(). isPresent()
67+ registry. schemaDefinition(). get(). isEqualTo(result1. schemaDefinition(). get())
68+
69+ }
70+
4871 def " test merge of schema types" () {
4972
5073 def spec1 = """
You can’t perform that action at this time.
0 commit comments