Skip to content

Commit c340d85

Browse files
committed
Handling for empty representations list
Closes gh-1057
1 parent ba1dcf0 commit c340d85

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

spring-graphql/src/main/java/org/springframework/graphql/data/federation/EntitiesDataFetcher.java

+3
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ public Mono<DataFetcherResult<List<Object>>> get(DataFetchingEnvironment env) {
7070
return Mono.error(new RepresentationException(
7171
Collections.emptyMap(), "Missing \"representations\" argument"));
7272
}
73+
if (representations.isEmpty()) {
74+
return Mono.just(DataFetcherResult.<List<Object>>newResult().data(Collections.emptyList()).build());
75+
}
7376

7477
Set<String> batchedTypes = new HashSet<>();
7578
List<Mono<?>> monoList = new ArrayList<>();

spring-graphql/src/test/java/org/springframework/graphql/data/federation/EntityMappingInvocationTests.java

+8
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ void fetchEntitiesWithExceptions() {
115115
assertAuthor(6, "George", "Orwell", helper);
116116
}
117117

118+
@Test // gh-1057
119+
void fetchEntitiesWithEmptyList() {
120+
Map<String, Object> vars = Map.of("representations", Collections.emptyList());
121+
ResponseHelper helper = executeWith(BookController.class, vars);
122+
123+
assertThat(helper.toEntity("_entities.length()", Integer.class)).isEqualTo(0);
124+
}
125+
118126
@ValueSource(classes = {BookListController.class, BookFluxController.class})
119127
@ParameterizedTest
120128
void batching(Class<?> controllerClass) {

0 commit comments

Comments
 (0)