Skip to content

Commit 663c3de

Browse files
authored
Merge pull request graphql-java#418 from kaseyreed/do-not-overwrite-top-level-schema-def
graphql-java#417 do not overwrite top level schema definition during type registry merge
2 parents 7242973 + 37ab74b commit 663c3de

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
@@ -57,8 +57,12 @@ public TypeDefinitionRegistry merge(TypeDefinitionRegistry typeRegistry) throws
5757
throw new SchemaProblem(errors);
5858
}
5959

60+
if (this.schema == null) {
61+
// ensure schema is not overwritten by merge
62+
this.schema = typeRegistry.schema;
63+
}
64+
6065
// ok commit to the merge
61-
this.schema = typeRegistry.schema;
6266
this.types.putAll(tempTypes);
6367
this.scalarTypes.putAll(tempScalarTypes);
6468
//

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)