Skip to content

Commit 37ab74b

Browse files
committed
do not overwrite top level schema definition during type registry merge
1 parent bad750c commit 37ab74b

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

src/main/java/graphql/schema/idl/TypeDefinitionRegistry.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff 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);

src/test/groovy/graphql/schema/idl/TypeDefinitionRegistryTest.groovy

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff 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 = """

0 commit comments

Comments
 (0)