Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/main/java/graphql/relay/SimpleListConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public Object get(DataFetchingEnvironment environment) {
int beforeOffset = getOffsetFromCursor(environment.<String>getArgument("before"), edges.size());
int end = Math.min(beforeOffset, edges.size());

if (begin > end) begin = end;

edges = edges.subList(begin, end);
if (edges.size() == 0) {
return emptyConnection();
Expand Down Expand Up @@ -104,4 +106,4 @@ private String createCursor(int offset) {
}


}
}
31 changes: 31 additions & 0 deletions src/test/groovy/graphql/relay/SimpleListConnectionTest.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package graphql.relay

import graphql.language.BooleanValue
import graphql.language.FloatValue
import graphql.language.IntValue
import graphql.language.StringValue
import graphql.relay.SimpleListConnection
import graphql.schema.DataFetchingEnvironment
import spock.lang.Specification
import spock.lang.Unroll

class SimpleListConnectionTest extends Specification {
def "invalid list indices handled"() {
given:
def testList = ["a", "b"]
def listConnection = new SimpleListConnection(testList)
def env = new DataFetchingEnvironment(null, ["after":createCursor(3)], null, null, null, null, null);

when:
Object item = listConnection.get(env);

then:
item instanceof graphql.relay.Connection
}

private static final String DUMMY_CURSOR_PREFIX = "simple-cursor";
private String createCursor(int offset) {
String string = graphql.relay.Base64.toBase64(DUMMY_CURSOR_PREFIX + Integer.toString(offset));
return string;
}
}