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/12 10:45:46 UTC

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

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 ca0b4f6  SLING-10309 - better example
ca0b4f6 is described below

commit ca0b4f6baae946ffb7b9f1ca3b579f1174c68855
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Wed May 12 12:45:31 2021 +0200

    SLING-10309 - better example
---
 README.md | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index a5b0e50..e3d0c57 100644
--- a/README.md
+++ b/README.md
@@ -159,7 +159,24 @@ for paginated results, following the [Relay Cursor Connections](https://relay.de
 With this utility class, you just need to supply an `Iterator` on your data, a function to generate a string that represents the cursor
 for a given object, and optional parameters to control the page start and length.
 
-The [GenericConnectionTest](./src/test/java/org/apache/sling/graphql/core/pagination/GenericConnectionTest.java) class has concrete examples of that.
+The [QueryDataFetcherComponent](./src/test/java/org/apache/sling/graphql/core/mocks/QueryDataFetcherComponent.java) test class has a 
+concrete example. The below code is sufficient to produce a paginated result according to the Relay spec, assuming the GraphQL schema
+contains the required types. We are working on a schema directive to generate those connection types automatically, but for now they
+can be added manually to a schema, like [the one used in this test](./src/test/resources/initial-content/apps/graphql/test/one/GQLschema.jsp).
+
+    // fake test data simulating a query
+    final List<Resource> data = new ArrayList<>();
+    data.add(env.getCurrentResource());
+    data.add(env.getCurrentResource().getParent());
+    data.add(env.getCurrentResource().getParent().getParent());
+
+    // how to build a unique cursor that points to one of our data objects
+    final Function<Resource, String> cursorStringProvider = r -> r.getPath();
+
+    // return a GenericConnection that the library will introspect and serialize
+    return new GenericConnection.Builder<>(data.iterator(), cursorStringProvider)
+      withLimit(5)
+      .build();
 
 ## Caching: Persisted queries API