Skip to content
This repository was archived by the owner on Feb 1, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ nbbuild/
dist/
nbdist/
.nb-gradle/

### vsCode ###
.vscode
/bin/
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ language: java

jdk:
- oraclejdk11
- oraclejdk8
- openjdk8

install:
- chmod -R 777 ./mvnw
- ./mvnw install -DskipTests=true -Dmaven.javadoc.skip=true -B -V


after_success:
- ./mvnw clean test jacoco:report coveralls:report -Dcoveralls.token=$COVERALLS
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@

/**
* Elide AutoConfiguration.
*
* @author olOwOlo
*/
@Configuration
@EnableConfigurationProperties(ElideProperties.class)
@ConditionalOnWebApplication
@AutoConfigureAfter({HibernateJpaAutoConfiguration.class, WebMvcAutoConfiguration.class})
@AutoConfigureAfter({ HibernateJpaAutoConfiguration.class, WebMvcAutoConfiguration.class })
public class ElideAutoConfiguration {

private static final Logger logger = LoggerFactory.getLogger(ElideAutoConfiguration.class);
Expand Down Expand Up @@ -83,7 +84,7 @@ public Elide elide(PlatformTransactionManager txManager,
elideProperties, true, ScrollMode.FORWARD_ONLY);

Elide elide = new Elide(new ElideSettingsBuilder(springDataStore)
.withJsonApiMapper(new JsonApiMapper(entityDictionary, objectMapper))
.withJsonApiMapper(new JsonApiMapper(objectMapper))
.withEntityDictionary(entityDictionary)
.withJoinFilterDialect(rsqlFilterDialect)
.withSubqueryFilterDialect(rsqlFilterDialect)
Expand All @@ -105,8 +106,8 @@ private void scanChecks(ConcurrentHashMap<String, Class<? extends Check>> checks
for (Class<?> clazz : ClassIndex.getAnnotated(ElideCheck.class)) {
ElideCheck elideCheck = clazz.getAnnotation(ElideCheck.class);
if (Check.class.isAssignableFrom(clazz)) {
logger.debug("Register Elide Check [{}] with expression [{}]",
clazz.getCanonicalName(), elideCheck.value());
logger.debug("Register Elide Check [{}] with expression [{}]", clazz.getCanonicalName(),
elideCheck.value());
checks.put(elideCheck.value(), clazz.asSubclass(Check.class));
} else {
throw new RuntimeException("The class[" + clazz.getCanonicalName()
Expand Down Expand Up @@ -144,10 +145,8 @@ private void scanLifeCycleHook(EntityDictionary entityDictionary, ApplicationCon
}

logger.debug("Register Elide Function Hook: bindTrigger({}, {}, \"{}\", {})",
entity.getCanonicalName(),
elideHook.lifeCycle().getSimpleName(),
elideHook.fieldOrMethodName(),
clazz.getCanonicalName());
entity.getCanonicalName(), elideHook.lifeCycle().getSimpleName(),
elideHook.fieldOrMethodName(), clazz.getCanonicalName());

} else {
throw new RuntimeException("The class[" + clazz.getCanonicalName()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
/*
* Copyright (c) 2018 the original author or authors.
*
* Licensed 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
*
* 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.
Expand Down Expand Up @@ -35,6 +32,7 @@
import com.yahoo.elide.graphql.ModelBuilder;
import com.yahoo.elide.graphql.PersistentResourceFetcher;
import com.yahoo.elide.security.User;

import graphql.ExecutionInput;
import graphql.ExecutionResult;
import graphql.GraphQL;
Expand All @@ -51,13 +49,13 @@
import org.slf4j.LoggerFactory;

/**
* GraphQLHandle.
* <br>
* Based on <a href="https://github.com/yahoo/elide/blob/master/elide-graphql/src/main/java/com/yahoo/elide/graphql/GraphQLEndpoint.java">GraphQLEndpoint.java</a>
* GraphQLHandle. <br>
* Based on <a href=
* "https://github.com/yahoo/elide/blob/master/elide-graphql/src/main/java/com/yahoo/elide/graphql/GraphQLEndpoint.java">GraphQLEndpoint.java</a>
* Latest commit is 9d6e11efa0ba26f81286c9b0a3b298467359900a.
* <ul>
* <li>SecurityContext -&gt; Object(opaqueUser)</li>
* <li>javax.ws.rs.core.Response -&gt; ElideResponse</li>
* <li>SecurityContext -&gt; Object(opaqueUser)</li>
* <li>javax.ws.rs.core.Response -&gt; ElideResponse</li>
* </ul>
*
* @author olOwOlo
Expand All @@ -81,14 +79,14 @@ public GraphQLHandle(Elide elide) {
this.elideSettings = elide.getElideSettings();
PersistentResourceFetcher fetcher = new PersistentResourceFetcher(elide.getElideSettings());
ModelBuilder builder = new ModelBuilder(elide.getElideSettings().getDictionary(), fetcher);
this.api = new GraphQL(builder.build());
this.api = GraphQL.newGraphQL(builder.build()).build();
}

/**
* Create handler.
*
* @param graphQLDocument post data as jsonapi document
* @param opaqueUser opaqueUser
* @param opaqueUser opaqueUser
* @return response
*/
public ElideResponse post(String graphQLDocument, Object opaqueUser) {
Expand All @@ -100,54 +98,53 @@ public ElideResponse post(String graphQLDocument, Object opaqueUser) {
topLevel = mapper.readTree(graphQLDocument);
} catch (IOException e) {
log.debug("Invalid json body provided to GraphQL", e);
// NOTE: Can't get at isVerbose setting here for hardcoding to false. If necessary, we can refactor
// NOTE: Can't get at isVerbose setting here for hardcoding to false. If
// necessary, we can refactor
// so this can be set appropriately.
return buildErrorResponse(new InvalidEntityBodyException(graphQLDocument), false);
}

Function<JsonNode, ElideResponse> executeRequest =
(node) -> executeGraphQLRequest(mapper, opaqueUser, graphQLDocument, node);
Function<JsonNode, ElideResponse> executeRequest = (node) -> executeGraphQLRequest(mapper,
opaqueUser, graphQLDocument, node);

if (topLevel.isArray()) {
Iterator<JsonNode> nodeIterator = topLevel.iterator();
Iterable<JsonNode> nodeIterable = () -> nodeIterator;
// NOTE: Create a non-parallel stream
// It's unclear whether or not the expectations of the caller would be that requests are intended
// It's unclear whether or not the expectations of the caller would be that
// requests are intended
// to run serially even outside of a single transaction. We should revisit this.
Stream<JsonNode> nodeStream = StreamSupport.stream(nodeIterable.spliterator(), false);
ArrayNode result = nodeStream
.map(executeRequest)
.map(response -> {
try {
return mapper.readTree(response.getBody());
} catch (IOException e) {
log.debug("Caught an IO exception while trying to read response body");
return JsonNodeFactory.instance.objectNode();
}
})
.reduce(JsonNodeFactory.instance.arrayNode(),
(arrayNode, node) -> arrayNode.add(node),
ArrayNode result = nodeStream.map(executeRequest).map(response -> {
try {
return mapper.readTree(response.getBody());
} catch (IOException e) {
log.debug("Caught an IO exception while trying to read response body");
return JsonNodeFactory.instance.objectNode();
}
})
.reduce(JsonNodeFactory.instance.arrayNode(), (arrayNode, node) -> arrayNode.add(node),
(left, right) -> left.addAll(right));
try {
return new ElideResponse(HttpStatus.SC_OK, mapper.writeValueAsString(result));
} catch (JsonProcessingException e) {
log.error("An unexpected error occurred trying to serialize array response.", e);
throw new RuntimeException(e); // 500
throw new RuntimeException(e); // 500
}
}

return executeRequest.apply(topLevel);
}

private ElideResponse executeGraphQLRequest(
ObjectMapper mapper,
private ElideResponse executeGraphQLRequest(ObjectMapper mapper,
Object opaqueUser,
String graphQLDocument,
JsonNode jsonDocument) {
boolean isVerbose = false;
try (DataStoreTransaction tx = elide.getDataStore().beginTransaction()) {
final User user = tx.accessUser(opaqueUser);
GraphQLRequestScope requestScope = new GraphQLRequestScope(tx, user, elide.getElideSettings());
GraphQLRequestScope requestScope = new GraphQLRequestScope(tx, user,
elide.getElideSettings());
isVerbose = requestScope.getPermissionExecutor().isVerbose();

if (!jsonDocument.has(QUERY)) {
Expand All @@ -156,20 +153,21 @@ private ElideResponse executeGraphQLRequest(

String query = jsonDocument.get(QUERY).asText();

// Logging all queries. It is recommended to put any private information that shouldn't be logged into
// Logging all queries. It is recommended to put any private information that
// shouldn't be logged into
// the "variables" section of your query. Variable values are not logged.
log.info("Processing GraphQL query:\n{}", query);

ExecutionInput.Builder executionInput = new ExecutionInput.Builder()
.context(requestScope)
ExecutionInput.Builder executionInput = new ExecutionInput.Builder().context(requestScope)
.query(query);

if (jsonDocument.has(OPERATION_NAME) && !jsonDocument.get(OPERATION_NAME).isNull()) {
executionInput.operationName(jsonDocument.get(OPERATION_NAME).asText());
}

if (jsonDocument.has(VARIABLES) && !jsonDocument.get(VARIABLES).isNull()) {
Map<String, Object> variables = mapper.convertValue(jsonDocument.get(VARIABLES), Map.class);
Map<String, Object> variables = mapper.convertValue(jsonDocument.get(VARIABLES),
Map.class);
executionInput.variables(variables);
}

Expand Down Expand Up @@ -201,7 +199,8 @@ private ElideResponse executeGraphQLRequest(
requestScope.getPermissionExecutor().printCheckStats();
}

return new ElideResponse(HttpStatus.SC_OK, mapper.writeValueAsString(result.toSpecification()));
return new ElideResponse(HttpStatus.SC_OK,
mapper.writeValueAsString(result.toSpecification()));
} catch (WebApplicationException e) {
log.debug("WebApplicationException", e);
throw e;
Expand Down Expand Up @@ -256,12 +255,13 @@ private ElideResponse buildErrorResponse(HttpStatusException error, boolean isVe
ObjectMapper mapper = elide.getMapper().getObjectMapper();
JsonNode errorNode;
if (!(error instanceof CustomErrorException) && elideSettings.isReturnErrorObjects()) {
ErrorObjects errors = ErrorObjects.builder().addError()
.with("message", isVerbose ? error.getVerboseMessage() : error.toString()).build();
ErrorObjects errors = ErrorObjects.builder()
.addError()
.with("message", isVerbose ? error.getVerboseMessage() : error.toString())
.build();
errorNode = mapper.convertValue(errors, JsonNode.class);
} else {
errorNode = isVerbose
? error.getVerboseErrorResponse().getRight()
errorNode = isVerbose ? error.getVerboseErrorResponse().getRight()
: error.getErrorResponse().getRight();
}
String errorBody;
Expand Down
13 changes: 8 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
~ limitations under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.illyasviel.elide</groupId>
Expand Down Expand Up @@ -92,12 +93,12 @@
<maven.compiler.testSource>1.8</maven.compiler.testSource>
<maven.compiler.testTarget>1.8</maven.compiler.testTarget>

<spring-boot.version>2.1.0.RELEASE</spring-boot.version>
<elide.version>4.2.10</elide.version>
<classindex.version>3.4</classindex.version>
<spring-boot.version>2.1.6.RELEASE</spring-boot.version>
<elide.version>4.4.5</elide.version>
<classindex.version>3.7</classindex.version>
<jaxb-api.version>2.3.0</jaxb-api.version>
<activation.version>1.1.1</activation.version>
<lombok.version>1.18.4</lombok.version>
<lombok.version>1.18.8</lombok.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -179,6 +180,7 @@
</dependencyManagement>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -246,6 +248,7 @@
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>

<profiles>
Expand Down