Skip to content

Commit 71b1f58

Browse files
committed
Fix IndexOutOfBoundsException for empty Window
Closes gh-775
1 parent a079d44 commit 71b1f58

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

spring-graphql/src/main/java/org/springframework/graphql/data/pagination/ConnectionFieldTypeVisitor.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ private <T> Object adapt(@Nullable Object container) {
217217
}
218218

219219
Collection<T> nodes = this.adapter.getContent(container);
220+
if (nodes.isEmpty()) {
221+
return EMPTY_CONNECTION;
222+
}
223+
220224
int index = 0;
221225
List<Edge<T>> edges = new ArrayList<>(nodes.size());
222226
for (T node : nodes) {

spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingPaginationTests.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,23 @@ void forwardPagination() {
6666
"}}}");
6767
}
6868

69+
@Test // gh-775
70+
void zeroResults() {
71+
72+
String document = BookSource.booksConnectionQuery("first:0, after:\"O_3\"");
73+
Mono<ExecutionGraphQlResponse> response = graphQlService().execute(document);
74+
75+
ResponseHelper.forResponse(response).assertData("""
76+
{"books":{\
77+
"edges":[],\
78+
"pageInfo":{\
79+
"startCursor":null,\
80+
"endCursor":null,\
81+
"hasPreviousPage":false,\
82+
"hasNextPage":false}}}"""
83+
);
84+
}
85+
6986
private TestExecutionGraphQlService graphQlService() {
7087

7188
ScrollPositionCursorStrategy cursorStrategy = new ScrollPositionCursorStrategy();

0 commit comments

Comments
 (0)