executePostJsonRequest(@RequestBody @Valid final GraphQLQueryRequest queryRequest) throws IOException {
- Authentication auth = SecurityContextHolder.getContext().getAuthentication();
-
- return graphQLExecutor.execute(queryRequest.getQuery(),
- queryRequest.getVariables()).toSpecification();
-
- }
-
- /**
- * Handle HTTP GET request.
- * The GraphQL query should be specified in the "query" query string.
- * i.e. http://server/graphql?query={query{name}}
- *
- * Query variables can be sent as a JSON-encoded string in an additional
- * query parameter called variables.
- * @param query encoded JSON string
- * @param variables encoded JSON string
- * @return {@link Map} response
- * @throws IOException
- */
- @GetMapping(value = PATH,
- consumes = {APPLICATION_GRAPHQL_VALUE},
- produces = MediaType.APPLICATION_JSON_VALUE)
- public Map executeGetQueryRequest(
- @RequestParam(name = "query") final String query,
- @RequestParam(name = "variables", required = false) final String variables) throws IOException {
- Map variablesMap = variablesStringToMap(variables);
-
- return graphQLExecutor.execute(query,
- variablesMap).toSpecification();
- }
-
- /**
- * Handle HTTP FORM POST request.
- * The GraphQL query should be specified in the "query" query parameter string.
- *
- * Query variables can be sent as a JSON-encoded string in an additional
- * query parameter called variables.
- * @param query encoded JSON string
- * @param variables encoded JSON string
- * @return {@link Map} response
- * @throws IOException
- */
- @PostMapping(value = PATH,
- consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE,
- produces = MediaType.APPLICATION_JSON_VALUE)
- public Map executePostFormRequest(
- @RequestParam(name = "query") final String query,
- @RequestParam(name = "variables", required = false) final String variables) throws IOException {
- Map variablesMap = variablesStringToMap(variables);
-
- return graphQLExecutor.execute(query,
- variablesMap).toSpecification();
- }
-
- /**
- * Handle POST with the "application/graphql" Content-Type header.
- * Treat the HTTP POST body contents as the GraphQL query string.
- * @param queryRequest a valid {@link GraphQLQueryRequest} input argument
- * @return {@link Map} response
- * @throws IOException
- */
- @PostMapping(value = PATH,
- consumes = APPLICATION_GRAPHQL_VALUE,
- produces = MediaType.APPLICATION_JSON_VALUE)
- public Map executePostApplicationGraphQL(
- @RequestBody final String query) throws IOException {
- return graphQLExecutor.execute(query,
- null).toSpecification();
- }
-
- /**
- * Convert String argument to a Map as expected by {@link GraphQLJpaExecutor#execute(String, Map)}. GraphiQL posts both
- * query and variables as JSON encoded String, so Spring MVC mapping is useless here.
- * See: http://graphql.org/learn/serving-over-http/
- * @param json JSON encoded string variables
- * @return a {@link HashMap} object of variable key-value pairs
- * @throws IOException
- */
- @SuppressWarnings("unchecked")
- private Map variablesStringToMap(final String json) throws IOException {
- Map variables = null;
-
- if (json != null && !json.isEmpty()) {
- variables = mapper.readValue(json,
- Map.class);
- }
-
- return variables;
- }
-
- /**
- * GraphQL JSON HTTP Request Wrapper Class
- */
- @Validated
- public static class GraphQLQueryRequest {
-
- @NotNull
- private String query;
-
- private Map variables;
-
- GraphQLQueryRequest() {
- }
-
- /**
- * @param query
- */
- public GraphQLQueryRequest(String query) {
- super();
- this.query = query;
- }
-
- /**
- * @return the query
- */
- public String getQuery() {
- return this.query;
- }
-
- /**
- * @param query the query to set
- */
- public void setQuery(String query) {
- this.query = query;
- }
-
- /**
- * @return the variables
- */
- public Map getVariables() {
- return this.variables;
- }
-
- /**
- * @param variables the variables to set
- */
- public void setVariables(Map variables) {
- this.variables = variables;
- }
- }
-}
diff --git a/services/web/src/test/java/org/activiti/cloud/services/graphql/autoconfigure/ActivitiGraphQLAutoConfigurationTest.java b/services/web/src/test/java/org/activiti/cloud/services/graphql/autoconfigure/ActivitiGraphQLAutoConfigurationTest.java
index 7cf194e..5228711 100644
--- a/services/web/src/test/java/org/activiti/cloud/services/graphql/autoconfigure/ActivitiGraphQLAutoConfigurationTest.java
+++ b/services/web/src/test/java/org/activiti/cloud/services/graphql/autoconfigure/ActivitiGraphQLAutoConfigurationTest.java
@@ -17,10 +17,6 @@
import static org.assertj.core.api.Assertions.assertThat;
-import com.introproventures.graphql.jpa.query.schema.GraphQLExecutor;
-import com.introproventures.graphql.jpa.query.schema.impl.GraphQLJpaExecutor;
-import graphql.schema.GraphQLSchema;
-import org.activiti.cloud.services.graphql.web.ActivitiGraphQLController;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -30,6 +26,11 @@
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.junit4.SpringRunner;
+import com.introproventures.graphql.jpa.query.schema.GraphQLExecutor;
+import com.introproventures.graphql.jpa.query.schema.impl.GraphQLJpaExecutor;
+import com.introproventures.graphql.jpa.query.web.GraphQLController;
+import graphql.schema.GraphQLSchema;
+
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class ActivitiGraphQLAutoConfigurationTest {
@@ -44,7 +45,7 @@ public class ActivitiGraphQLAutoConfigurationTest {
private GraphQLExecutor graphQLExecutor;
@Autowired
- private ActivitiGraphQLController graphQLController;
+ private GraphQLController graphQLController;
@SpringBootApplication
static class Application {
diff --git a/services/web/src/test/java/org/activiti/cloud/services/graphql/web/ActivitiGraphQLControllerTest.java b/services/web/src/test/java/org/activiti/cloud/services/graphql/web/ActivitiGraphQLControllerTest.java
index eef2842..09e9ef3 100644
--- a/services/web/src/test/java/org/activiti/cloud/services/graphql/web/ActivitiGraphQLControllerTest.java
+++ b/services/web/src/test/java/org/activiti/cloud/services/graphql/web/ActivitiGraphQLControllerTest.java
@@ -27,11 +27,6 @@
import java.util.HashMap;
import java.util.Map;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.introproventures.graphql.jpa.query.schema.impl.GraphQLJpaExecutor;
-import graphql.ExecutionResultImpl;
-import org.activiti.cloud.services.graphql.web.ActivitiGraphQLController.GraphQLQueryRequest;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -46,9 +41,18 @@
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.introproventures.graphql.jpa.query.schema.impl.GraphQLJpaExecutor;
+import com.introproventures.graphql.jpa.query.web.GraphQLController;
+import com.introproventures.graphql.jpa.query.web.GraphQLController.GraphQLQueryRequest;
+import graphql.ExecutionResultImpl;
+
@RunWith(SpringRunner.class)
-@WebMvcTest(controllers = ActivitiGraphQLController.class)
+@WebMvcTest(controllers = GraphQLController.class)
public class ActivitiGraphQLControllerTest {
+
+ public static final String APPLICATION_GRAPHQL_VALUE = "application/graphql";
@Autowired
private MockMvc mockmvc;
@@ -60,7 +64,7 @@ public class ActivitiGraphQLControllerTest {
private ObjectMapper mapper;
@Configuration
- @Import(ActivitiGraphQLController.class)
+ @Import(GraphQLController.class)
static class Config {
}
@@ -101,7 +105,7 @@ private ResultActions perform(final String json) throws Exception {
public void testGraphqlGetQueryNoVariables() throws Exception {
mockmvc.perform(get("/graphql")
.param("query", "{Tasks(where: {name: {EQ: \"name\"}}){select{id}}}")
- .contentType(ActivitiGraphQLController.APPLICATION_GRAPHQL_VALUE)
+ .contentType(APPLICATION_GRAPHQL_VALUE)
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
@@ -115,7 +119,7 @@ public void testGraphqlGetQueryNoVariables() throws Exception {
public void testGraphqlPostQuery() throws Exception {
mockmvc.perform(post("/graphql")
.content("{Tasks(where: {name: {EQ: \"name\"}}){select{id}}}")
- .contentType(ActivitiGraphQLController.APPLICATION_GRAPHQL_VALUE)
+ .contentType(APPLICATION_GRAPHQL_VALUE)
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
@@ -131,7 +135,7 @@ public void testGraphqlQueryGetWithNullVariables() throws Exception {
mockmvc.perform(get("/graphql")
.param("query", "{Tasks(where: {name: {EQ: \"name\"}}){select{id}}}")
.param("variables", (String) null)
- .contentType(ActivitiGraphQLController.APPLICATION_GRAPHQL_VALUE)
+ .contentType(APPLICATION_GRAPHQL_VALUE)
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
@@ -150,7 +154,7 @@ public void testGraphqlGetQueryWithVariables() throws Exception {
mockmvc.perform(get("/graphql")
.param("query", "{Tasks(where: {name: {EQ: \"name\"}}){select{id}}}")
.param("variables", variablesStr)
- .contentType(ActivitiGraphQLController.APPLICATION_GRAPHQL_VALUE)
+ .contentType(APPLICATION_GRAPHQL_VALUE)
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
@@ -165,7 +169,7 @@ public void testGraphqlQueryGetWithEmptyVariables() throws Exception {
mockmvc.perform(get("/graphql")
.param("query", "{Tasks(where: {name: {EQ: \"name\"}}){select{id}}}")
.param("variables", "")
- .contentType(ActivitiGraphQLController.APPLICATION_GRAPHQL_VALUE))
+ .contentType(APPLICATION_GRAPHQL_VALUE))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
;
diff --git a/starter/src/main/resources/metadata.properties b/starter/src/main/resources/metadata.properties
new file mode 100644
index 0000000..036fa72
--- /dev/null
+++ b/starter/src/main/resources/metadata.properties
@@ -0,0 +1,3 @@
+activiti.cloud.service.type=notifications-graphql
+
+spring.jpa.open-in-view=false
\ No newline at end of file
diff --git a/starter/src/test/java/org/activiti/cloud/notifications/graphql/starter/ActivitiGraphQLStarterIT.java b/starter/src/test/java/org/activiti/cloud/notifications/graphql/starter/ActivitiGraphQLStarterIT.java
index 5785898..74245ba 100644
--- a/starter/src/test/java/org/activiti/cloud/notifications/graphql/starter/ActivitiGraphQLStarterIT.java
+++ b/starter/src/test/java/org/activiti/cloud/notifications/graphql/starter/ActivitiGraphQLStarterIT.java
@@ -17,12 +17,16 @@
import static org.assertj.core.api.Assertions.assertThat;
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonMappingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import graphql.ExecutionResult;
-import graphql.GraphQLError;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.time.Duration;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.concurrent.TimeoutException;
+
import org.activiti.api.runtime.model.impl.BPMNMessageImpl;
import org.activiti.api.runtime.model.impl.BPMNSignalImpl;
import org.activiti.api.runtime.model.impl.BPMNTimerImpl;
@@ -52,7 +56,7 @@
import org.activiti.cloud.api.process.model.impl.events.CloudProcessStartedEventImpl;
import org.activiti.cloud.notifications.graphql.test.EngineEventsMessageProducer;
import org.activiti.cloud.notifications.graphql.test.EngineEventsMessageProducer.EngineEvents;
-import org.activiti.cloud.services.graphql.web.ActivitiGraphQLController.GraphQLQueryRequest;
+import org.activiti.cloud.services.notifications.graphql.web.api.GraphQLQueryResult;
import org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessage;
import org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessageType;
import org.activiti.cloud.services.query.model.ProcessDefinitionEntity;
@@ -69,7 +73,6 @@
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.cloud.stream.annotation.EnableBinding;
-import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
@@ -77,6 +80,12 @@
import org.springframework.http.ResponseEntity;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.test.context.junit4.SpringRunner;
+
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.introproventures.graphql.jpa.query.web.GraphQLController.GraphQLQueryRequest;
import reactor.core.publisher.Mono;
import reactor.core.publisher.ReplayProcessor;
import reactor.netty.NettyPipeline;
@@ -84,17 +93,6 @@
import reactor.netty.http.client.HttpClient.WebsocketSender;
import reactor.test.StepVerifier;
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.time.Duration;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.TimeoutException;
-
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class ActivitiGraphQLStarterIT {
@@ -1041,13 +1039,13 @@ public void testGraphqlWsSubprotocolServerUnauthorized() throws JsonProcessingEx
public void testGraphql() {
GraphQLQueryRequest query = new GraphQLQueryRequest("{Tasks(where:{name:{EQ: \"" + TASK_NAME + "\"}}){select{id assignee priority}}}");
- ResponseEntity entity = rest.postForEntity(GRAPHQL_URL, new HttpEntity<>(query,authHeaders), Result.class);
+ ResponseEntity entity = rest.postForEntity(GRAPHQL_URL, new HttpEntity<>(query,authHeaders), GraphQLQueryResult.class);
assertThat(entity.getStatusCode())
.describedAs(entity.toString())
.isEqualTo(HttpStatus.OK);
- Result result = entity.getBody();
+ GraphQLQueryResult result = entity.getBody();
assertThat(result).isNotNull();
assertThat(result.getErrors())
@@ -1065,7 +1063,7 @@ public void testGraphqlUnauthorized() {
keycloakTokenProducer.setKeycloakTestUser(HRUSER);
authHeaders = keycloakTokenProducer.authorizationHeaders();
- ResponseEntity entity = rest.postForEntity(GRAPHQL_URL, new HttpEntity<>(query,authHeaders), Result.class);
+ ResponseEntity entity = rest.postForEntity(GRAPHQL_URL, new HttpEntity<>(query,authHeaders), GraphQLQueryResult.class);
assertThat(HttpStatus.FORBIDDEN)
.describedAs(entity.toString())
@@ -1096,13 +1094,13 @@ public void testGraphqlWhere() {
" }");
// @formatter:on
- ResponseEntity entity = rest.postForEntity(GRAPHQL_URL, new HttpEntity<>(query, authHeaders), Result.class);
+ ResponseEntity entity = rest.postForEntity(GRAPHQL_URL, new HttpEntity<>(query, authHeaders), GraphQLQueryResult.class);
assertThat(entity.getStatusCode())
.describedAs(entity.toString())
.isEqualTo(HttpStatus.OK);
- Result result = entity.getBody();
+ GraphQLQueryResult result = entity.getBody();
assertThat(result).isNotNull();
assertThat(result.getErrors())
@@ -1144,13 +1142,13 @@ public void testGraphqlNesting() {
+ "}");
// @formatter:on
- ResponseEntity entity = rest.postForEntity(GRAPHQL_URL, new HttpEntity<>(query, authHeaders), Result.class);
+ ResponseEntity entity = rest.postForEntity(GRAPHQL_URL, new HttpEntity<>(query, authHeaders), GraphQLQueryResult.class);
assertThat(entity.getStatusCode())
.describedAs(entity.toString())
.isEqualTo(HttpStatus.OK);
- Result result = entity.getBody();
+ GraphQLQueryResult result = entity.getBody();
assertThat(result).isNotNull();
assertThat(result.getErrors())
@@ -1178,19 +1176,19 @@ public void testGraphqlReverse() {
);
// @formatter:on
- ResponseEntity entity = rest.postForEntity(GRAPHQL_URL, new HttpEntity<>(query, authHeaders), Result.class);
+ ResponseEntity entity = rest.postForEntity(GRAPHQL_URL, new HttpEntity<>(query, authHeaders), GraphQLQueryResult.class);
assertThat(entity.getStatusCode())
.describedAs(entity.toString())
.isEqualTo(HttpStatus.OK);
- Result result = entity.getBody();
+ GraphQLQueryResult result = entity.getBody();
assertThat(result).isNotNull();
assertThat(result.getErrors())
.isNull();
- assertThat(((Map) result.getData()).get("ProcessVariables")).isNotNull();
+ assertThat(result.getData().get("ProcessVariables")).isNotNull();
}
@Test
@@ -1202,13 +1200,13 @@ public void testGraphqlArguments() throws JsonParseException, JsonMappingExcepti
query.setVariables(variables);
- ResponseEntity entity = rest.postForEntity(GRAPHQL_URL, new HttpEntity<>(query, authHeaders), Result.class);
+ ResponseEntity entity = rest.postForEntity(GRAPHQL_URL, new HttpEntity<>(query, authHeaders), GraphQLQueryResult.class);
assertThat(entity.getStatusCode())
.describedAs(entity.toString())
.isEqualTo(HttpStatus.OK);
- Result result = entity.getBody();
+ GraphQLQueryResult result = entity.getBody();
assertThat(result).isNotNull();
assertThat(result.getErrors())
@@ -1234,9 +1232,6 @@ class StringObjectMapBuilder extends MapBuilder, K, V> {
-
- protected static final SpelExpressionParser PARSER = new SpelExpressionParser();
-
private final Map map = new LinkedHashMap<>();
public B put(K key, V value) {
@@ -1255,57 +1250,3 @@ protected final B _this() {
}
-
-class Result implements ExecutionResult {
-
- private Map data;
- private List errors;
- private Map