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 09:56:13 UTC
[sling-org-apache-sling-graphql-core] branch SLING-10309/experiment
updated: SLING-10309 - move GenericConnection to a specific helpers package
and add integration test for it
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 1f2b518 SLING-10309 - move GenericConnection to a specific helpers package and add integration test for it
1f2b518 is described below
commit 1f2b518a7d18dace3abea21dd9497161af743a34
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Wed May 12 11:52:43 2021 +0200
SLING-10309 - move GenericConnection to a specific helpers package and add integration test for it
---
.../helpers/pagination}/GenericConnection.java | 2 +-
.../core/helpers/pagination/package-info.java | 26 +++++++++++++
.../graphql/core/it/GraphQLCoreTestSupport.java | 5 ++-
.../sling/graphql/core/it/GraphQLServletIT.java | 2 +-
.../sling/graphql/core/it/ServerSideQueryIT.java | 14 ++++++-
.../core/mocks/QueryDataFetcherComponent.java | 45 ++++++++++++++++++++++
.../core/pagination/GenericConnectionTest.java | 2 +-
.../core/pagination/PaginatedHumansTest.java | 2 +-
.../apps/graphql/test/one/GQLschema.jsp | 22 +++++++++++
.../apps/graphql/test/one/query.json.gql | 24 ++++++++++++
10 files changed, 136 insertions(+), 8 deletions(-)
diff --git a/src/main/java/org/apache/sling/graphql/api/pagination/helpers/GenericConnection.java b/src/main/java/org/apache/sling/graphql/core/helpers/pagination/GenericConnection.java
similarity index 99%
rename from src/main/java/org/apache/sling/graphql/api/pagination/helpers/GenericConnection.java
rename to src/main/java/org/apache/sling/graphql/core/helpers/pagination/GenericConnection.java
index 1ebfabf..d380fb2 100644
--- a/src/main/java/org/apache/sling/graphql/api/pagination/helpers/GenericConnection.java
+++ b/src/main/java/org/apache/sling/graphql/core/helpers/pagination/GenericConnection.java
@@ -17,7 +17,7 @@
* under the License.
*/
- package org.apache.sling.graphql.api.pagination.helpers;
+ package org.apache.sling.graphql.core.helpers.pagination;
import java.util.ArrayList;
import java.util.Iterator;
diff --git a/src/main/java/org/apache/sling/graphql/core/helpers/pagination/package-info.java b/src/main/java/org/apache/sling/graphql/core/helpers/pagination/package-info.java
new file mode 100644
index 0000000..49b7bc4
--- /dev/null
+++ b/src/main/java/org/apache/sling/graphql/core/helpers/pagination/package-info.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+ /**
+ * This package contains APIs which are independent of
+ * a specific implementation of the underlying graphQL engine.
+ */
+@Version("0.0.1")
+package org.apache.sling.graphql.core.helpers.pagination;
+import org.osgi.annotation.versioning.Version;
diff --git a/src/test/java/org/apache/sling/graphql/core/it/GraphQLCoreTestSupport.java b/src/test/java/org/apache/sling/graphql/core/it/GraphQLCoreTestSupport.java
index 943e44f..2d6cc7e 100644
--- a/src/test/java/org/apache/sling/graphql/core/it/GraphQLCoreTestSupport.java
+++ b/src/test/java/org/apache/sling/graphql/core/it/GraphQLCoreTestSupport.java
@@ -36,6 +36,7 @@ import org.apache.johnzon.mapper.MapperBuilder;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.engine.SlingRequestProcessor;
+import org.apache.sling.graphql.core.mocks.QueryDataFetcherComponent;
import org.apache.sling.graphql.core.mocks.TestDataFetcherComponent;
import org.apache.sling.servlethelpers.MockSlingHttpServletResponse;
import org.apache.sling.servlethelpers.internalrequests.SlingInternalRequest;
@@ -111,8 +112,8 @@ public abstract class GraphQLCoreTestSupport extends TestSupport {
return testProbeBuilder;
}
- protected Option pipeDataFetcher() {
- return buildBundleWithBnd(TestDataFetcherComponent.class);
+ protected Option testDataFetchers() {
+ return buildBundleWithBnd(TestDataFetcherComponent.class, QueryDataFetcherComponent.class);
}
protected Option slingQuickstart() {
diff --git a/src/test/java/org/apache/sling/graphql/core/it/GraphQLServletIT.java b/src/test/java/org/apache/sling/graphql/core/it/GraphQLServletIT.java
index 9e78a1e..ccf1344 100644
--- a/src/test/java/org/apache/sling/graphql/core/it/GraphQLServletIT.java
+++ b/src/test/java/org/apache/sling/graphql/core/it/GraphQLServletIT.java
@@ -88,7 +88,7 @@ public class GraphQLServletIT extends GraphQLCoreTestSupport {
public Option[] configuration() {
return new Option[]{
baseConfiguration(),
- pipeDataFetcher(),
+ testDataFetchers(),
factoryConfiguration("org.apache.sling.resource.presence.internal.ResourcePresenter")
.put("path", "/content/graphql/two")
.asOption(),
diff --git a/src/test/java/org/apache/sling/graphql/core/it/ServerSideQueryIT.java b/src/test/java/org/apache/sling/graphql/core/it/ServerSideQueryIT.java
index 7825b94..461a046 100644
--- a/src/test/java/org/apache/sling/graphql/core/it/ServerSideQueryIT.java
+++ b/src/test/java/org/apache/sling/graphql/core/it/ServerSideQueryIT.java
@@ -36,7 +36,7 @@ import org.ops4j.pax.exam.spi.reactors.PerClass;
import org.ops4j.pax.exam.util.Filter;
import org.osgi.framework.BundleContext;
-import static org.junit.Assert.assertThat;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.ops4j.pax.exam.cm.ConfigurationAdminOptions.factoryConfiguration;
@@ -62,7 +62,7 @@ public class ServerSideQueryIT extends GraphQLCoreTestSupport {
public Option[] configuration() {
return new Option[]{
baseConfiguration(),
- pipeDataFetcher(),
+ testDataFetchers(),
factoryConfiguration("org.apache.sling.resource.presence.internal.ResourcePresenter")
.put("path", "/apps/graphql/test/one/json.gql")
.asOption(),
@@ -88,4 +88,14 @@ public class ServerSideQueryIT extends GraphQLCoreTestSupport {
new ReplacingSchemaProvider("oneSchemaResource", "NOT_THIS_ONE").register(bundleContext, defaultSchemaProvider, 1);
assertDefaultContent(".REPLACED", "REPLACED");
}
+
+ @Test
+ public void testPaginatedQuery() throws Exception {
+ final String json = getContent("graphql/one.query.json");
+ assertThat(json, hasJsonPath("$.data.oneSchemaQuery.pageInfo.startCursor"));
+ assertThat(json, hasJsonPath("$.data.oneSchemaQuery.edges[0].node.path", equalTo("/content/graphql/one")));
+ assertThat(json, hasJsonPath("$.data.oneSchemaQuery.edges[1].node.path", equalTo("/content/graphql")));
+ assertThat(json, hasJsonPath("$.data.oneSchemaQuery.edges[1].node.resourceType", equalTo("graphql/test/root")));
+ assertThat(json, hasJsonPath("$.data.oneSchemaQuery.edges[2].node.path", equalTo("/content")));
+ }
}
diff --git a/src/test/java/org/apache/sling/graphql/core/mocks/QueryDataFetcherComponent.java b/src/test/java/org/apache/sling/graphql/core/mocks/QueryDataFetcherComponent.java
new file mode 100644
index 0000000..33f6b9b
--- /dev/null
+++ b/src/test/java/org/apache/sling/graphql/core/mocks/QueryDataFetcherComponent.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.graphql.core.mocks;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.function.Function;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.graphql.api.SlingDataFetcher;
+import org.apache.sling.graphql.api.SlingDataFetcherEnvironment;
+import org.apache.sling.graphql.core.helpers.pagination.GenericConnection;
+import org.osgi.service.component.annotations.Component;
+
+@Component(service=SlingDataFetcher.class, property = { "name=test/query"})
+public class QueryDataFetcherComponent implements SlingDataFetcher<Object> {
+
+ @Override
+ public Object get(SlingDataFetcherEnvironment env) throws Exception {
+ // Not a real query, just simulating that to test pagination
+ final List<Resource> data = new ArrayList<>();
+ data.add(env.getCurrentResource());
+ data.add(env.getCurrentResource().getParent());
+ data.add(env.getCurrentResource().getParent().getParent());
+ final Function<Resource, String> cursorStringProvider = r -> r.getPath();
+ return new GenericConnection.Builder<>(data.iterator(), cursorStringProvider).build();
+ }
+}
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 ce008ec..6fe247c 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
@@ -32,7 +32,7 @@ import java.util.stream.StreamSupport;
import org.apache.sling.graphql.api.pagination.Connection;
import org.apache.sling.graphql.api.pagination.Cursor;
import org.apache.sling.graphql.api.pagination.Edge;
-import org.apache.sling.graphql.api.pagination.helpers.GenericConnection;
+import org.apache.sling.graphql.core.helpers.pagination.GenericConnection;
import org.junit.Test;
public class GenericConnectionTest {
diff --git a/src/test/java/org/apache/sling/graphql/core/pagination/PaginatedHumansTest.java b/src/test/java/org/apache/sling/graphql/core/pagination/PaginatedHumansTest.java
index b6a3c6f..0322ce0 100644
--- a/src/test/java/org/apache/sling/graphql/core/pagination/PaginatedHumansTest.java
+++ b/src/test/java/org/apache/sling/graphql/core/pagination/PaginatedHumansTest.java
@@ -31,12 +31,12 @@ import org.apache.sling.graphql.core.mocks.TestUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.apache.sling.graphql.core.engine.ResourceQueryTestBase;
+import org.apache.sling.graphql.core.helpers.pagination.GenericConnection;
import org.apache.sling.graphql.core.mocks.HumanDTO;
import org.apache.sling.graphql.api.SlingDataFetcher;
import org.apache.sling.graphql.api.SlingDataFetcherEnvironment;
import org.apache.sling.graphql.api.pagination.Connection;
import org.apache.sling.graphql.api.pagination.Cursor;
-import org.apache.sling.graphql.api.pagination.helpers.GenericConnection;
import org.junit.Test;
public class PaginatedHumansTest extends ResourceQueryTestBase {
diff --git a/src/test/resources/initial-content/apps/graphql/test/one/GQLschema.jsp b/src/test/resources/initial-content/apps/graphql/test/one/GQLschema.jsp
index ff09228..dbe2a5a 100644
--- a/src/test/resources/initial-content/apps/graphql/test/one/GQLschema.jsp
+++ b/src/test/resources/initial-content/apps/graphql/test/one/GQLschema.jsp
@@ -26,9 +26,31 @@ directive @fetcher(
type Query {
oneSchemaResource : SlingResource @fetcher(name:"test/pipe" source:"$")
+ oneSchemaQuery : SlingResourceConnection @fetcher(name:"test/query")
}
type SlingResource {
path: String
resourceType: String
+}
+
+# The connection-specific parts of the schema might be
+# generated based on a schema directive later, but
+# writing them "by hand" also works
+
+type PageInfo {
+ startCursor : String
+ endCursor : String
+ hasPreviousPage : Boolean
+ hasNextPage : Boolean
+}
+
+type SlingResourceEdge {
+ cursor: String
+ node: SlingResource
+}
+
+type SlingResourceConnection {
+ edges : [SlingResourceEdge]
+ pageInfo : PageInfo
}
\ No newline at end of file
diff --git a/src/test/resources/initial-content/apps/graphql/test/one/query.json.gql b/src/test/resources/initial-content/apps/graphql/test/one/query.json.gql
new file mode 100644
index 0000000..80d1c7e
--- /dev/null
+++ b/src/test/resources/initial-content/apps/graphql/test/one/query.json.gql
@@ -0,0 +1,24 @@
+# * Licensed to the Apache Software Foundation (ASF) under one
+# * or more contributor license agreements. See the NOTICE file
+# * distributed with this work for additional information
+# * regarding copyright ownership. The ASF licenses this file
+# * to you under the Apache License, Version 2.0 (the
+# * "License"); you may not use this file except in compliance
+# * with the License. You may obtain a copy of the License at
+# *
+# * http://www.apache.org/licenses/LICENSE-2.0
+# *
+# * Unless required by applicable law or agreed to in writing,
+# * software distributed under the License is distributed on an
+# * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# * KIND, either express or implied. See the License for the
+# * specific language governing permissions and limitations
+# * under the License.
+
+# Define the query for this resource type, selector and extension
+{ oneSchemaQuery
+ {
+ pageInfo { startCursor endCursor hasPreviousPage hasNextPage }
+ edges { cursor node { path resourceType } }
+ }
+}
\ No newline at end of file