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 09:02:56 UTC

[sling-org-apache-sling-graphql-core] branch SLING-10309/experiment updated: tweaks

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 94d91ee  tweaks
94d91ee is described below

commit 94d91ee42406d31ec900d4274d351057e006be11
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Tue May 11 11:02:36 2021 +0200

    tweaks
---
 .../java/org/apache/sling/graphql/api/pagination/Cursor.java |  5 ++++-
 .../org/apache/sling/graphql/core/engine/PaginationTest.java | 12 ++++++------
 2 files changed, 10 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 975502f..c4509da 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
@@ -24,7 +24,10 @@ import java.util.Base64;
 import org.jetbrains.annotations.NotNull;
 import org.osgi.annotation.versioning.ProviderType;
 
-/** Edges provide paginated data as per https://relay.dev/graphql/connections.htm */
+/** Cursor for our paginated results.
+ *  Base64-encoded to express the fact that it's meant to
+ *  be opaque.
+ */
  @ProviderType
 public class Cursor {
     private final String rawValue;
diff --git a/src/test/java/org/apache/sling/graphql/core/engine/PaginationTest.java b/src/test/java/org/apache/sling/graphql/core/engine/PaginationTest.java
index dcee1f3..26d9448 100644
--- a/src/test/java/org/apache/sling/graphql/core/engine/PaginationTest.java
+++ b/src/test/java/org/apache/sling/graphql/core/engine/PaginationTest.java
@@ -41,10 +41,10 @@ import org.junit.Test;
 
 public class PaginationTest extends ResourceQueryTestBase {
 
-    static class ConnectionDataFetcher implements SlingDataFetcher<Object> {
+    static class HumansPageFetcher implements SlingDataFetcher<Object> {
         private List<HumanDTO> humans = new ArrayList<>();
 
-        ConnectionDataFetcher(List<HumanDTO> humans) {
+        HumansPageFetcher(List<HumanDTO> humans) {
             this.humans = humans;
         }
 
@@ -56,6 +56,9 @@ public class PaginationTest extends ResourceQueryTestBase {
         }
     }
 
+    // TODO this class should be generalized so that data can be provided as 
+    // a data source (Stream?) with "skip after cursor" functionality, and the
+    // rest of this class is then generic.
     static class HumansResultPage implements ResultsPage<HumanDTO>,PageInfo {
 
         private final Cursor startCursor;
@@ -67,9 +70,6 @@ public class PaginationTest extends ResourceQueryTestBase {
         HumansResultPage(List<HumanDTO> humans, String cursor, int limit) {
             this.startCursor = new Cursor(Cursor.decode(cursor));
 
-            // TODO this should be generalized so that data can be provided as 
-            // a data source with "skip after cursor" functionality, and the
-            // rest of this class is then generic
             boolean inRange = false;
             int remaining = limit;
             for(HumanDTO dto : humans) {
@@ -142,7 +142,7 @@ public class PaginationTest extends ResourceQueryTestBase {
             humans.add(new HumanDTO("human-" + i, "Luke-" + i, "Tatooine"));
         }
         TestUtil.registerSlingTypeResolver(context.bundleContext(), "character/resolver", new CharacterTypeResolver());
-        TestUtil.registerSlingDataFetcher(context.bundleContext(), "humans/paginated", new ConnectionDataFetcher(humans));
+        TestUtil.registerSlingDataFetcher(context.bundleContext(), "humans/paginated", new HumansPageFetcher(humans));
     }
 
     private void assertPageInfo(String json, Cursor startCursor, Cursor endCursor, Boolean hasPreviousPage, Boolean hasNextPage) {