Fix IndexOutOfBoundsException for empty Window

Closes gh-775
This commit is contained in:
rstoyanchev
2023-09-01 16:38:35 +01:00
parent a079d442c8
commit 71b1f5868b
2 changed files with 21 additions and 0 deletions

View File

@@ -217,6 +217,10 @@ public final class ConnectionFieldTypeVisitor extends GraphQLTypeVisitorStub {
}
Collection<T> nodes = this.adapter.getContent(container);
if (nodes.isEmpty()) {
return EMPTY_CONNECTION;
}
int index = 0;
List<Edge<T>> edges = new ArrayList<>(nodes.size());
for (T node : nodes) {

View File

@@ -66,6 +66,23 @@ public class SchemaMappingPaginationTests {
"}}}");
}
@Test // gh-775
void zeroResults() {
String document = BookSource.booksConnectionQuery("first:0, after:\"O_3\"");
Mono<ExecutionGraphQlResponse> response = graphQlService().execute(document);
ResponseHelper.forResponse(response).assertData("""
{"books":{\
"edges":[],\
"pageInfo":{\
"startCursor":null,\
"endCursor":null,\
"hasPreviousPage":false,\
"hasNextPage":false}}}"""
);
}
private TestExecutionGraphQlService graphQlService() {
ScrollPositionCursorStrategy cursorStrategy = new ScrollPositionCursorStrategy();