Skip to content

Commit a46d462

Browse files
Tomas Alabesbbakerman
authored andcommitted
fix: Handling empty list in SimpleListCollection
1 parent 5caa4f2 commit a46d462

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/main/java/graphql/relay/SimpleListConnection.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ public Connection<T> get(DataFetchingEnvironment environment) {
4646

4747
List<Edge<T>> edges = buildEdges();
4848

49+
if (edges.size() == 0) {
50+
return emptyConnection();
51+
}
52+
4953
ConnectionCursor firstPresliceCursor = edges.get(0).getCursor();
5054
ConnectionCursor lastPresliceCursor = edges.get(edges.size() - 1).getCursor();
5155

src/test/groovy/graphql/relay/SimpleListConnectionTest.groovy

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,16 @@ class SimpleListConnectionTest extends Specification {
8181
connection.getEdges().size() == 3
8282
connection.getEdges().get(1).getNode() == null
8383
}
84+
85+
def "can accept an empty list"() {
86+
given:
87+
def empty = []
88+
def env = newDataFetchingEnvironment().executionContext(Mock(ExecutionContext)).build()
89+
90+
when:
91+
def connection = new SimpleListConnection(empty).get(env)
92+
93+
then:
94+
connection.getEdges().size() == 0
95+
}
8496
}

0 commit comments

Comments
 (0)