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/09 14:30:56 UTC
[sling-whiteboard] branch master updated: Fix paginated queries and
adapt README
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-whiteboard.git
The following commit(s) were added to refs/heads/master by this push:
new 3c307fe Fix paginated queries and adapt README
3c307fe is described below
commit 3c307fe03e78c0d0156a6d1962f98f8b4066b00c
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Wed Jun 9 16:30:38 2021 +0200
Fix paginated queries and adapt README
---
remote-content-api/sample-graphql-api/README.md | 54 ++++++++++++++--------
.../samples/graphql/DocumentsDataFetcher.java | 2 +-
.../samples/graphql/FetcherContext.java | 10 ++--
.../samples/graphql/FoldersDataFetcher.java | 2 +-
.../resources/SLING-INF/initial-content/ROOT.json | 2 +-
5 files changed, 41 insertions(+), 29 deletions(-)
diff --git a/remote-content-api/sample-graphql-api/README.md b/remote-content-api/sample-graphql-api/README.md
index d6d5f25..8ceaefb 100644
--- a/remote-content-api/sample-graphql-api/README.md
+++ b/remote-content-api/sample-graphql-api/README.md
@@ -13,17 +13,19 @@ of this one and then, in this folder, run
Then open http://localhost:8080 - which might require logging in
at http://localhost:8080/system/console first.
-This should redirect you to the main GraphQL endpoint, currently
-http://localhost:8080/graphql.json - which is meant to be used by a GraphQL client.
+This should redirect you to a test GraphQL endpoint, currently
+http://localhost:8080/content.N.json - which is meant to be used by a GraphQL client.
+
+Note that with that _N_ selector, _every resource is a GraphQL endpoint_. This helps contextualize
+requests, querying a `Folder` or `Document` without a _path_ parameter for example addresses
+the current Resource. I'm thinking of implementing selector-driven prepared GraphQL requests
+so that a GET request to _/content.N.folders.json_ for example would execute the prepared
+_folders_ query against that Resource.
The standard `MAVEN_OPTS` environment variable can be used to setup
debugging, as the above does not fork and starts the application with
the Maven JVM.
-At this point, this module does not use snapshots from the sibling modules
-in the Sling whiteboard - this bundle is the only snapshot declared in the
-feature model file that thats this.
-
## Test Content
The test content uses `com.adobe.aem.guides:aem-guides-wknd.ui.content.sample` which is MIT
@@ -32,6 +34,8 @@ we don't really care about the details of these node types besides their names.
## Example GraphQL queries
+See the [Schema for the API plane N](src/main/resources/schemas/default/N.GQLschema.jsp) for possible Queries and Mutations.
+
{
folders(limit: 55, after: "L2NvbnRlbnQvYXJ0aWNsZXMvbXVzaWM=") {
pageInfo {
@@ -62,11 +66,13 @@ we don't really care about the details of these node types besides their names.
}
}
}
- document {
+ document(path:"/content/wknd") {
path
header {
parent
+ resourceType
}
+ body
}
}
@@ -127,25 +133,35 @@ we don't really care about the details of these node types besides their names.
lang:"repoinit",
script:"""
# comments work here
- set properties on /open-for-all
- set title to "Look, I changed the title again!"
- end
+ create path /open-for-all/ok
""")
{
success
output
+ help
}
}
{
- documents(
- lang:"sql2020",
- query:"""
- select * from nt:unstructured as R
- where [sling:resourceType] = 'wknd/components/carousel'
- and isdescendantnode(R, '/content/wknd/us/en')
- """)
- {
- path
+ documents(query: "//open-for-all/*") {
+ edges {
+ node {
+ path
+ }
+ }
+ }
+ }
+
+ {
+ documents(lang: "sql2020", query: """
+ select * from nt:unstructured as R
+ where [sling:resourceType] = 'wknd/components/carousel'
+ and isdescendantnode(R, '/content/wknd/us/en')
+ """) {
+ edges {
+ node {
+ path
+ }
+ }
}
}
diff --git a/remote-content-api/sample-graphql-api/src/main/java/org/apache/sling/remotecontent/samples/graphql/DocumentsDataFetcher.java b/remote-content-api/sample-graphql-api/src/main/java/org/apache/sling/remotecontent/samples/graphql/DocumentsDataFetcher.java
index bad235c..58579a2 100644
--- a/remote-content-api/sample-graphql-api/src/main/java/org/apache/sling/remotecontent/samples/graphql/DocumentsDataFetcher.java
+++ b/remote-content-api/sample-graphql-api/src/main/java/org/apache/sling/remotecontent/samples/graphql/DocumentsDataFetcher.java
@@ -36,7 +36,7 @@ public class DocumentsDataFetcher implements SlingDataFetcher<Connection<Documen
@Override
public @Nullable Connection<Document> get(@NotNull SlingDataFetcherEnvironment e) throws Exception {
- final FetcherContext ctx = new FetcherContext(e, false);
+ final FetcherContext ctx = new FetcherContext(e, true);
// Use a suffix as we might not keep these built-in language in the long term
final String langSuffix = "2020";
diff --git a/remote-content-api/sample-graphql-api/src/main/java/org/apache/sling/remotecontent/samples/graphql/FetcherContext.java b/remote-content-api/sample-graphql-api/src/main/java/org/apache/sling/remotecontent/samples/graphql/FetcherContext.java
index 63dbbe5..f44ce9a 100644
--- a/remote-content-api/sample-graphql-api/src/main/java/org/apache/sling/remotecontent/samples/graphql/FetcherContext.java
+++ b/remote-content-api/sample-graphql-api/src/main/java/org/apache/sling/remotecontent/samples/graphql/FetcherContext.java
@@ -40,12 +40,8 @@ class FetcherContext {
r = r.getResourceResolver().getResource(path);
}
currentResource = r;
- if(includePagination) {
- afterCursor = Cursor.fromEncodedString(e.getArgument(AFTER_ARG));
- limit = e.getArgument(LIMIT_ARG, DEFAULT_LIMIT);
- } else {
- afterCursor = null;
- limit = -1;
- }
+ limit = e.getArgument(LIMIT_ARG, DEFAULT_LIMIT);
+ final String after = e.getArgument(AFTER_ARG, null);
+ afterCursor = includePagination ? Cursor.fromEncodedString(after) : null;
}
}
\ No newline at end of file
diff --git a/remote-content-api/sample-graphql-api/src/main/java/org/apache/sling/remotecontent/samples/graphql/FoldersDataFetcher.java b/remote-content-api/sample-graphql-api/src/main/java/org/apache/sling/remotecontent/samples/graphql/FoldersDataFetcher.java
index 194b7af..e4c7fb6 100644
--- a/remote-content-api/sample-graphql-api/src/main/java/org/apache/sling/remotecontent/samples/graphql/FoldersDataFetcher.java
+++ b/remote-content-api/sample-graphql-api/src/main/java/org/apache/sling/remotecontent/samples/graphql/FoldersDataFetcher.java
@@ -36,7 +36,7 @@ public class FoldersDataFetcher implements SlingDataFetcher<Connection<Folder>>
@Override
public @Nullable Connection<Folder> get(@NotNull SlingDataFetcherEnvironment e) throws Exception {
- final FetcherContext ctx = new FetcherContext(e, false);
+ final FetcherContext ctx = new FetcherContext(e, true);
final String xpathQuery = String.format(
"/jcr:root%s//element(*, nt:folder) order by jcr:path ascending option(traversal fail)",
diff --git a/remote-content-api/sample-graphql-api/src/main/resources/SLING-INF/initial-content/ROOT.json b/remote-content-api/sample-graphql-api/src/main/resources/SLING-INF/initial-content/ROOT.json
index 087ddde..6bebd0e 100644
--- a/remote-content-api/sample-graphql-api/src/main/resources/SLING-INF/initial-content/ROOT.json
+++ b/remote-content-api/sample-graphql-api/src/main/resources/SLING-INF/initial-content/ROOT.json
@@ -1,4 +1,4 @@
{
"sling:resourceType" : "sling:redirect",
- "sling:target" : "/graphql.json"
+ "sling:target" : "/content.N.json"
}
\ No newline at end of file