Skip to content

Commit 8d5436a

Browse files
committed
Allow more than 1 type runtime wiring if it is for a datafetcher for a non-overlapping child field
1 parent ee9570a commit 8d5436a

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,17 @@ public Builder type(String typeName, UnaryOperator<TypeRuntimeWiring.Builder> bu
313313
public Builder type(TypeRuntimeWiring typeRuntimeWiring) {
314314
String typeName = typeRuntimeWiring.getTypeName();
315315
Map<String, DataFetcher> typeDataFetchers = dataFetchers.computeIfAbsent(typeName, k -> new LinkedHashMap<>());
316+
317+
Map<String, DataFetcher> additionalFieldDataFetchers = typeRuntimeWiring.getFieldDataFetchers();
316318
if (strictMode && !typeDataFetchers.isEmpty()) {
317-
throw new StrictModeWiringException(format("The type %s has already been defined", typeName));
319+
// Check if the existing type wiring contains overlapping DataFetcher definitions
320+
for (String fieldName : additionalFieldDataFetchers.keySet()) {
321+
if (typeDataFetchers.containsKey(fieldName)) {
322+
throw new StrictModeWiringException(format("The field %s on type %s has already been defined", fieldName, typeName));
323+
}
324+
}
318325
}
319-
typeDataFetchers.putAll(typeRuntimeWiring.getFieldDataFetchers());
326+
typeDataFetchers.putAll(additionalFieldDataFetchers);
320327

321328
DataFetcher<?> defaultDataFetcher = typeRuntimeWiring.getDefaultDataFetcher();
322329
if (defaultDataFetcher != null) {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ class RuntimeWiringTest extends Specification {
206206

207207
then:
208208
def e1 = thrown(StrictModeWiringException)
209-
e1.message == "The type Foo has already been defined"
209+
e1.message == "The field foo on type Foo has already been defined"
210210

211211
when:
212212
RuntimeWiring.newRuntimeWiring()
@@ -253,6 +253,7 @@ class RuntimeWiringTest extends Specification {
253253
def runtimeWiring1 = RuntimeWiring.newRuntimeWiring()
254254
.type(TypeRuntimeWiring.newTypeWiring("Foo").dataFetcher("foo", DF1))
255255
.type(TypeRuntimeWiring.newTypeWiring("Foo").dataFetcher("bar", DF2))
256+
.build()
256257

257258
then:
258259
noExceptionThrown()
@@ -313,7 +314,7 @@ class RuntimeWiringTest extends Specification {
313314

314315
then:
315316
noExceptionThrown()
316-
runtimeWiring1.getDataFetchers().get("Foo").get("bar") == DF1
317+
runtimeWiring1.getDataFetchers().get("Foo").get("foo") == DF2
317318

318319
when:
319320
def runtimeWiring2 = RuntimeWiring.newRuntimeWiring()

0 commit comments

Comments
 (0)