You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2021/06/24 13:16:48 UTC
[sling-org-apache-sling-graphql-core] 03/03: SLING-10541 - fix
error with empty result set
This is an automated email from the ASF dual-hosted git repository.
bdelacretaz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-graphql-core.git
commit de82d3b80f921515b3e901ee8dba38986de28161
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Thu Jun 24 15:15:14 2021 +0200
SLING-10541 - fix error with empty result set
---
.../java/org/apache/sling/graphql/helpers/GenericConnection.java | 3 ++-
.../sling/graphql/core/pagination/GenericConnectionTest.java | 8 ++++++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/apache/sling/graphql/helpers/GenericConnection.java b/src/main/java/org/apache/sling/graphql/helpers/GenericConnection.java
index aaefe55..7b3d1be 100644
--- a/src/main/java/org/apache/sling/graphql/helpers/GenericConnection.java
+++ b/src/main/java/org/apache/sling/graphql/helpers/GenericConnection.java
@@ -74,6 +74,7 @@ public final class GenericConnection<T> implements Connection<T>, PageInfo {
throw new IllegalStateException("Already initialized");
}
initialized = true;
+ final boolean anyData = dataIterator.hasNext();
// Need to visit the stream first to setup the PageInfo, which graphql-java
// apparently uses before visiting all the edges
@@ -111,7 +112,7 @@ public final class GenericConnection<T> implements Connection<T>, PageInfo {
}
}
- if(!inRange && limit > 0) {
+ if(anyData && !inRange && limit > 0) {
throw new SlingGraphQLException("Start cursor not found in supplied data:" + startAfter);
}
if(hasPreviousPage == null) {
diff --git a/src/test/java/org/apache/sling/graphql/core/pagination/GenericConnectionTest.java b/src/test/java/org/apache/sling/graphql/core/pagination/GenericConnectionTest.java
index d71d09a..a531ebf 100644
--- a/src/test/java/org/apache/sling/graphql/core/pagination/GenericConnectionTest.java
+++ b/src/test/java/org/apache/sling/graphql/core/pagination/GenericConnectionTest.java
@@ -19,10 +19,12 @@
package org.apache.sling.graphql.core.pagination;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.Arrays;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
@@ -185,4 +187,10 @@ public class GenericConnectionTest {
assertTrue(iex.getMessage().contains("aximum"));
}
}
+
+ @Test
+ public void testEmptyResultSet() {
+ final Connection<String> empty = new GenericConnection.Builder<String>(Collections.emptyIterator(), s -> s).build();
+ assertFalse("Expecting no data", empty.getEdges().iterator().hasNext());
+ }
}