Handling for empty representations list

Closes gh-1057
This commit is contained in:
rstoyanchev
2024-09-17 11:46:00 +01:00
parent ba1dcf0baf
commit c340d85494
2 changed files with 11 additions and 0 deletions

View File

@@ -70,6 +70,9 @@ final class EntitiesDataFetcher implements DataFetcher<Mono<DataFetcherResult<Li
return Mono.error(new RepresentationException(
Collections.emptyMap(), "Missing \"representations\" argument"));
}
if (representations.isEmpty()) {
return Mono.just(DataFetcherResult.<List<Object>>newResult().data(Collections.emptyList()).build());
}
Set<String> batchedTypes = new HashSet<>();
List<Mono<?>> monoList = new ArrayList<>();

View File

@@ -115,6 +115,14 @@ public class EntityMappingInvocationTests {
assertAuthor(6, "George", "Orwell", helper);
}
@Test // gh-1057
void fetchEntitiesWithEmptyList() {
Map<String, Object> vars = Map.of("representations", Collections.emptyList());
ResponseHelper helper = executeWith(BookController.class, vars);
assertThat(helper.toEntity("_entities.length()", Integer.class)).isEqualTo(0);
}
@ValueSource(classes = {BookListController.class, BookFluxController.class})
@ParameterizedTest
void batching(Class<?> controllerClass) {