|
3 | 3 | import graphql.ExecutionInput; |
4 | 4 | import graphql.ExecutionResult; |
5 | 5 |
|
| 6 | +import javax.servlet.http.HttpServletResponse; |
6 | 7 | import java.io.IOException; |
7 | 8 | import java.io.Writer; |
8 | 9 | import java.util.Iterator; |
|
13 | 14 | public class TestBatchExecutionHandler implements BatchExecutionHandler { |
14 | 15 |
|
15 | 16 | @Override |
16 | | - public void handleBatch(GraphQLBatchedInvocationInput batchedInvocationInput, Writer writer, GraphQLObjectMapper graphQLObjectMapper, |
| 17 | + public void handleBatch(GraphQLBatchedInvocationInput batchedInvocationInput, HttpServletResponse response, GraphQLObjectMapper graphQLObjectMapper, |
17 | 18 | BiFunction<GraphQLInvocationInput, ExecutionInput, ExecutionResult> queryFunction) { |
18 | 19 | List<ExecutionResult> results = batchedInvocationInput.getExecutionInputs().parallelStream() |
19 | 20 | .limit(2) |
20 | 21 | .map(input -> queryFunction.apply(batchedInvocationInput, input)) |
21 | 22 | .collect(Collectors.toList()); |
22 | | - writeResults(results, writer, graphQLObjectMapper); |
| 23 | + writeResults(results, response, graphQLObjectMapper); |
23 | 24 | } |
24 | 25 |
|
25 | | - private void writeResults(List<ExecutionResult> results, Writer writer, GraphQLObjectMapper mapper) { |
| 26 | + private void writeResults(List<ExecutionResult> results, HttpServletResponse response, GraphQLObjectMapper mapper) { |
| 27 | + response.setContentType(AbstractGraphQLHttpServlet.APPLICATION_JSON_UTF8); |
| 28 | + response.setStatus(AbstractGraphQLHttpServlet.STATUS_OK); |
26 | 29 | try { |
| 30 | + Writer writer = response.getWriter(); |
27 | 31 | writer.write("["); |
28 | 32 | Iterator<ExecutionResult> iter = results.iterator(); |
29 | 33 | while (iter.hasNext()) { |
|
0 commit comments