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 2020/06/12 11:49:30 UTC
[sling-org-apache-sling-graphql-core] branch master updated: Add
logging and adapt to internal requests API changes
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-org-apache-sling-graphql-core.git
The following commit(s) were added to refs/heads/master by this push:
new 85c2be0 Add logging and adapt to internal requests API changes
85c2be0 is described below
commit 85c2be028b7e82d3b7ab6e2db2a483277a2249df
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Fri Jun 12 13:49:16 2020 +0200
Add logging and adapt to internal requests API changes
---
.../graphql/core/engine/GraphQLResourceQuery.java | 4 ++++
.../graphql/core/schema/DefaultSchemaProvider.java | 20 ++++++++++++++------
.../graphql/core/it/GraphQLCoreTestSupport.java | 6 +++---
3 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/src/main/java/org/apache/sling/graphql/core/engine/GraphQLResourceQuery.java b/src/main/java/org/apache/sling/graphql/core/engine/GraphQLResourceQuery.java
index f8851b3..5242ef2 100644
--- a/src/main/java/org/apache/sling/graphql/core/engine/GraphQLResourceQuery.java
+++ b/src/main/java/org/apache/sling/graphql/core/engine/GraphQLResourceQuery.java
@@ -86,22 +86,26 @@ public class GraphQLResourceQuery {
} catch(Exception e) {
final ScriptException up = new ScriptException("Schema provider failed");
up.initCause(e);
+ log.info("Schema provider Exception", up);
throw up;
}
log.info("Resource {} maps to GQL schema {}", r.getPath(), schemaDef);
try {
final GraphQLSchema schema = buildSchema(schemaDef, fetchersSelector, r);
final GraphQL graphQL = GraphQL.newGraphQL(schema).build();
+ log.debug("Executing query\n[{}]\nat [{}] with variables [{}]", query, r.getPath(), variables);
ExecutionInput ei = ExecutionInput.newExecutionInput()
.query(query)
.variables(variables)
.build();
final ExecutionResult result = graphQL.execute(ei);
+ log.debug("ExecutionResult.isDataPresent={}", result.isDataPresent());
return result;
} catch(Exception e) {
final ScriptException up = new ScriptException(
String.format("Query failed for Resource %s: schema=%s, query=%s", r.getPath(), schemaDef, query));
up.initCause(e);
+ log.info("GraphQL Query Exception", up);
throw up;
}
}
diff --git a/src/main/java/org/apache/sling/graphql/core/schema/DefaultSchemaProvider.java b/src/main/java/org/apache/sling/graphql/core/schema/DefaultSchemaProvider.java
index 9f6ee46..2127b0d 100644
--- a/src/main/java/org/apache/sling/graphql/core/schema/DefaultSchemaProvider.java
+++ b/src/main/java/org/apache/sling/graphql/core/schema/DefaultSchemaProvider.java
@@ -28,9 +28,12 @@ import org.apache.sling.api.resource.Resource;
import org.apache.sling.engine.SlingRequestProcessor;
import org.apache.sling.graphql.api.SchemaProvider;
import org.apache.sling.servlethelpers.internalrequests.InternalRequest;
+import org.apache.sling.servlethelpers.internalrequests.SlingInternalRequest;
import org.osgi.framework.Constants;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/** Provides a Resource-specific GraphQL Schema, as text */
@Component(service = SchemaProvider.class, immediate = true, property = {
@@ -39,6 +42,8 @@ import org.osgi.service.component.annotations.Reference;
Constants.SERVICE_VENDOR + "=The Apache Software Foundation" })
public class DefaultSchemaProvider implements SchemaProvider {
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
public static final int SERVICE_RANKING = Integer.MAX_VALUE - 100;
public static final String SCHEMA_EXTENSION = "GQLschema";
public static final String DEFAULT_SCHEMA = "";
@@ -48,15 +53,18 @@ public class DefaultSchemaProvider implements SchemaProvider {
@Override
public String getSchema(Resource r, String [] selectors) throws IOException {
- // TODO using a servletRequest should be more efficient but that doesn't
- // seem to work so far - schema JSP is not executed in integration tests
- final InternalRequest req = InternalRequest
- .slingRequest(r.getResourceResolver(), requestProcessor, r.getPath())
+ // TODO using a servletRequest should be more efficient - not tested yet
+ final InternalRequest req =
+ new SlingInternalRequest(r.getResourceResolver(), requestProcessor, r.getPath())
+ .withResourceType(r.getResourceType())
+ .withResourceSuperType(r.getResourceSuperType())
.withSelectors(selectors)
.withExtension(SCHEMA_EXTENSION)
- .execute();
+ ;
+
+ log.debug("Getting GraphQL Schema for {}: {}", r.getPath(), req);
- if(req.getStatus() == HttpServletResponse.SC_OK) {
+ if(req.execute().getStatus() == HttpServletResponse.SC_OK) {
return req.getResponseAsString();
} else {
return DEFAULT_SCHEMA;
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 c29c7f9..e2a2a0b 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
@@ -28,7 +28,7 @@ import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.graphql.core.json.JsonSerializer;
import org.apache.sling.graphql.core.mocks.TestDataFetcherComponent;
import org.apache.sling.servlethelpers.MockSlingHttpServletResponse;
-import org.apache.sling.servlethelpers.internalrequests.InternalRequest;
+import org.apache.sling.servlethelpers.internalrequests.SlingInternalRequest;
import org.apache.sling.testing.paxexam.TestSupport;
import org.junit.Before;
import org.ops4j.pax.exam.Option;
@@ -165,8 +165,8 @@ public abstract class GraphQLCoreTestSupport extends TestSupport {
final int [] statusParam = expectedStatus == -1 ? null : new int[] { expectedStatus };
- return (MockSlingHttpServletResponse)InternalRequest
- .slingRequest(resourceResolver, requestProcessor, path)
+ return (MockSlingHttpServletResponse)
+ new SlingInternalRequest(resourceResolver, requestProcessor, path)
.withRequestMethod(method)
.withParameters(params)
.withContentType(contentType)