Skip to content

Commit 556afe6

Browse files
authored
fix: change ExecutionResult to return Map type using toSpecification() (#71)
1 parent 007014b commit 556afe6

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

graphql-jpa-query-boot-starter/src/main/java/com/introproventures/graphql/jpa/query/web/GraphQLController.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,10 @@ public GraphQLController(GraphQLExecutor graphQLExecutor, ObjectMapper mapper) {
8282
@PostMapping(value = PATH,
8383
consumes = {MediaType.APPLICATION_JSON_VALUE},
8484
produces = MediaType.APPLICATION_JSON_VALUE)
85-
public ExecutionResult postJson(@RequestBody @Valid final GraphQLQueryRequest queryRequest) throws IOException
85+
public Map<String, Object> postJson(@RequestBody @Valid final GraphQLQueryRequest queryRequest) throws IOException
8686
{
87-
return graphQLExecutor.execute(queryRequest.getQuery(), queryRequest.getVariables());
87+
return graphQLExecutor.execute(queryRequest.getQuery(), queryRequest.getVariables())
88+
.toSpecification();
8889
}
8990

9091
/**
@@ -103,13 +104,14 @@ public ExecutionResult postJson(@RequestBody @Valid final GraphQLQueryRequest qu
103104
@GetMapping(value = PATH,
104105
consumes = {APPLICATION_GRAPHQL_VALUE},
105106
produces=MediaType.APPLICATION_JSON_VALUE)
106-
public ExecutionResult getQuery(
107+
public Map<String, Object> getQuery(
107108
@RequestParam(name="query") final String query,
108109
@RequestParam(name="variables", required = false) final String variables) throws IOException
109110
{
110111
Map<String, Object> variablesMap = variablesStringToMap(variables);
111112

112-
return graphQLExecutor.execute(query, variablesMap);
113+
return graphQLExecutor.execute(query, variablesMap)
114+
.toSpecification();
113115
}
114116

115117
/**
@@ -127,13 +129,14 @@ public ExecutionResult getQuery(
127129
@PostMapping(value = PATH,
128130
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE,
129131
produces=MediaType.APPLICATION_JSON_VALUE)
130-
public ExecutionResult postForm(
132+
public Map<String, Object> postForm(
131133
@RequestParam(name="query") final String query,
132134
@RequestParam(name="variables", required = false) final String variables) throws IOException
133135
{
134136
Map<String, Object> variablesMap = variablesStringToMap(variables);
135137

136-
return graphQLExecutor.execute(query, variablesMap);
138+
return graphQLExecutor.execute(query, variablesMap)
139+
.toSpecification();
137140
}
138141

139142
/**
@@ -148,10 +151,11 @@ public ExecutionResult postForm(
148151
@PostMapping(value = PATH,
149152
consumes = APPLICATION_GRAPHQL_VALUE,
150153
produces=MediaType.APPLICATION_JSON_VALUE)
151-
public ExecutionResult postApplicationGraphQL(
154+
public Map<String, Object> postApplicationGraphQL(
152155
@RequestBody final String query) throws IOException
153156
{
154-
return graphQLExecutor.execute(query, null);
157+
return graphQLExecutor.execute(query, null)
158+
.toSpecification();
155159
}
156160

157161
/**

graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/web/GraphQLControllerIT.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
import java.util.List;
2121
import java.util.Map;
2222

23+
import com.fasterxml.jackson.core.JsonParseException;
24+
import com.fasterxml.jackson.databind.JsonMappingException;
25+
import com.introproventures.graphql.jpa.query.web.GraphQLController.GraphQLQueryRequest;
26+
import graphql.ExecutionResult;
27+
import graphql.GraphQLError;
28+
import lombok.Value;
2329
import org.junit.Assert;
2430
import org.junit.Test;
2531
import org.junit.runner.RunWith;
@@ -33,14 +39,6 @@
3339
import org.springframework.http.ResponseEntity;
3440
import org.springframework.test.context.junit4.SpringRunner;
3541

36-
import com.fasterxml.jackson.core.JsonParseException;
37-
import com.fasterxml.jackson.databind.JsonMappingException;
38-
import com.introproventures.graphql.jpa.query.web.GraphQLController.GraphQLQueryRequest;
39-
40-
import graphql.ExecutionResult;
41-
import graphql.GraphQLError;
42-
import lombok.Value;
43-
4442
@RunWith(SpringRunner.class)
4543
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
4644
public class GraphQLControllerIT {
@@ -62,7 +60,7 @@ public void testGraphql() {
6260

6361
Result result = entity.getBody();
6462
Assert.assertNotNull(result);
65-
Assert.assertTrue(result.getErrors().toString(), result.getErrors().isEmpty());
63+
Assert.assertNull(result.getErrors());
6664
Assert.assertEquals("{Books={select=[{title=War and Peace, genre=NOVEL}]}}", result.getData().toString());
6765
}
6866

@@ -81,7 +79,7 @@ public void testGraphqlArguments() throws JsonParseException, JsonMappingExcepti
8179

8280
Result result = entity.getBody();
8381
Assert.assertNotNull(result);
84-
Assert.assertTrue(result.getErrors().toString(), result.getErrors().isEmpty());
82+
Assert.assertNull(result.getErrors());
8583
Assert.assertEquals("{Books={select=[{title=War and Peace, genre=NOVEL}]}}", result.getData().toString());
8684
}
8785
}

0 commit comments

Comments
 (0)