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/05/11 17:01:03 UTC
[sling-org-apache-sling-graphql-core] branch SLING-10309/experiment
updated: SLING-10309 - test zero limit
This is an automated email from the ASF dual-hosted git repository.
bdelacretaz pushed a commit to branch SLING-10309/experiment
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-graphql-core.git
The following commit(s) were added to refs/heads/SLING-10309/experiment by this push:
new 16bad68 SLING-10309 - test zero limit
16bad68 is described below
commit 16bad68a94023b05e40e98797a714d4cc14df0a7
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Tue May 11 19:00:46 2021 +0200
SLING-10309 - test zero limit
---
.../org/apache/sling/graphql/api/pagination/Cursor.java | 4 ----
.../graphql/api/pagination/helpers/GenericConnection.java | 2 +-
.../sling/graphql/core/engine/PaginatedHumansTest.java | 15 +++++++++++++--
3 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/src/main/java/org/apache/sling/graphql/api/pagination/Cursor.java b/src/main/java/org/apache/sling/graphql/api/pagination/Cursor.java
index 24311cb..bc391e4 100644
--- a/src/main/java/org/apache/sling/graphql/api/pagination/Cursor.java
+++ b/src/main/java/org/apache/sling/graphql/api/pagination/Cursor.java
@@ -34,10 +34,6 @@ public class Cursor {
private final String rawValue;
private final String encoded;
- /** These constants can be used to identify uninitialized cursors */
- public static final String INVALID_CURSOR_KEY = "$INVALID$CURSOR$" + Cursor.class.getName();
- public static final String ENCODED_INVALID_CURSOR_KEY = Cursor.encode(INVALID_CURSOR_KEY);
-
public Cursor(String rawValue) {
this.rawValue = rawValue == null ? "" : rawValue;
this.encoded = encode(this.rawValue);
diff --git a/src/main/java/org/apache/sling/graphql/api/pagination/helpers/GenericConnection.java b/src/main/java/org/apache/sling/graphql/api/pagination/helpers/GenericConnection.java
index 8cd8aa0..06527b3 100644
--- a/src/main/java/org/apache/sling/graphql/api/pagination/helpers/GenericConnection.java
+++ b/src/main/java/org/apache/sling/graphql/api/pagination/helpers/GenericConnection.java
@@ -124,7 +124,7 @@ public class GenericConnection<T> implements Connection<T> {
}
}
- if(!inRange) {
+ if(!inRange && maxItemsReturned > 0) {
throw new RuntimeException("Start cursor not found in supplied data:" + startAfter);
}
pageInfo.hasNextPage = dataIterator.hasNext();
diff --git a/src/test/java/org/apache/sling/graphql/core/engine/PaginatedHumansTest.java b/src/test/java/org/apache/sling/graphql/core/engine/PaginatedHumansTest.java
index e3a134c..6e4dd3d 100644
--- a/src/test/java/org/apache/sling/graphql/core/engine/PaginatedHumansTest.java
+++ b/src/test/java/org/apache/sling/graphql/core/engine/PaginatedHumansTest.java
@@ -70,8 +70,8 @@ public class PaginatedHumansTest extends ResourceQueryTestBase {
}
private void assertPageInfo(String json, Cursor startCursor, Cursor endCursor, Boolean hasPreviousPage, Boolean hasNextPage) {
- assertThat(json, hasJsonPath("$.data.paginatedHumans.pageInfo.startCursor", equalTo(startCursor.toString())));
- assertThat(json, hasJsonPath("$.data.paginatedHumans.pageInfo.endCursor", equalTo(endCursor.toString())));
+ assertThat(json, hasJsonPath("$.data.paginatedHumans.pageInfo.startCursor", equalTo(startCursor == null ? null : startCursor.toString())));
+ assertThat(json, hasJsonPath("$.data.paginatedHumans.pageInfo.endCursor", equalTo(endCursor == null ? null: endCursor.toString())));
assertThat(json, hasJsonPath("$.data.paginatedHumans.pageInfo.hasPreviousPage", equalTo(hasPreviousPage)));
assertThat(json, hasJsonPath("$.data.paginatedHumans.pageInfo.hasNextPage", equalTo(hasNextPage)));
}
@@ -124,6 +124,17 @@ public class PaginatedHumansTest extends ResourceQueryTestBase {
}
@Test
+ public void zeroLimit() throws Exception {
+ final Cursor start = new Cursor("human-94");
+ final String json = queryJSON("{ paginatedHumans(after:\"" + start + "\", limit:0) {"
+ + " pageInfo { startCursor endCursor hasPreviousPage hasNextPage }"
+ + " edges { cursor node { id name }}"
+ +"}}");
+ assertThat(json, hasJsonPath("$.data.paginatedHumans.edges.length()", equalTo(0)));
+ assertPageInfo(json, null, null, false, true);
+ }
+
+ @Test
public void afterCursorNotFound() throws Exception {
final Cursor notInDataSet = new Cursor("This is not a key from our data set");
final String json = queryJSON("{ paginatedHumans(after:\"" + notInDataSet + "\", limit:60) {"