@@ -73,6 +73,12 @@ public abstract class AbstractGraphQLHttpServlet extends HttpServlet implements
7373 @ Deprecated
7474 protected abstract GraphQLObjectMapper getGraphQLObjectMapper ();
7575
76+ /**
77+ * @deprecated override {@link #getConfiguration()} instead
78+ */
79+ @ Deprecated
80+ protected abstract GraphQLBatchExecutionHandlerFactory getBatchExecutionHandlerFactory ();
81+
7682 /**
7783 * @deprecated override {@link #getConfiguration()} instead
7884 */
@@ -85,6 +91,7 @@ protected GraphQLConfiguration getConfiguration() {
8591 .with (getGraphQLObjectMapper ())
8692 .with (isAsyncServletMode ())
8793 .with (listeners )
94+ .with (getBatchExecutionHandlerFactory ())
8895 .build ();
8996 }
9097
@@ -113,6 +120,7 @@ public void init(ServletConfig servletConfig) {
113120 GraphQLInvocationInputFactory invocationInputFactory = configuration .getInvocationInputFactory ();
114121 GraphQLObjectMapper graphQLObjectMapper = configuration .getObjectMapper ();
115122 GraphQLQueryInvoker queryInvoker = configuration .getQueryInvoker ();
123+ GraphQLBatchExecutionHandlerFactory batchExecutionHandlerFactory = configuration .getBatchExecutionHandlerFactory ();
116124
117125 String path = request .getPathInfo ();
118126 if (path == null ) {
@@ -125,7 +133,7 @@ public void init(ServletConfig servletConfig) {
125133 if (query != null ) {
126134
127135 if (isBatchedQuery (query )) {
128- queryBatched (queryInvoker , graphQLObjectMapper , invocationInputFactory .createReadOnly (graphQLObjectMapper .readBatchedGraphQLRequest (query ), request , response ), response );
136+ queryBatched (batchExecutionHandlerFactory , queryInvoker , graphQLObjectMapper , invocationInputFactory .createReadOnly (graphQLObjectMapper .readBatchedGraphQLRequest (query ), request , response ), response );
129137 } else {
130138 final Map <String , Object > variables = new HashMap <>();
131139 if (request .getParameter ("variables" ) != null ) {
@@ -147,6 +155,7 @@ public void init(ServletConfig servletConfig) {
147155 GraphQLInvocationInputFactory invocationInputFactory = configuration .getInvocationInputFactory ();
148156 GraphQLObjectMapper graphQLObjectMapper = configuration .getObjectMapper ();
149157 GraphQLQueryInvoker queryInvoker = configuration .getQueryInvoker ();
158+ GraphQLBatchExecutionHandlerFactory batchExecutionHandlerFactory = configuration .getBatchExecutionHandlerFactory ();
150159
151160 try {
152161 if (APPLICATION_GRAPHQL .equals (request .getContentType ())) {
@@ -181,7 +190,7 @@ public void init(ServletConfig servletConfig) {
181190 GraphQLBatchedInvocationInput invocationInput =
182191 invocationInputFactory .create (graphQLRequests , request , response );
183192 invocationInput .getContext ().setParts (fileItems );
184- queryBatched (queryInvoker , graphQLObjectMapper , invocationInput , response );
193+ queryBatched (batchExecutionHandlerFactory , queryInvoker , graphQLObjectMapper , invocationInput , response );
185194 return ;
186195 } else {
187196 GraphQLRequest graphQLRequest ;
@@ -207,7 +216,7 @@ public void init(ServletConfig servletConfig) {
207216 InputStream inputStream = asMarkableInputStream (request .getInputStream ());
208217
209218 if (isBatchedQuery (inputStream )) {
210- queryBatched (queryInvoker , graphQLObjectMapper , invocationInputFactory .create (graphQLObjectMapper .readBatchedGraphQLRequest (inputStream ), request , response ), response );
219+ queryBatched (batchExecutionHandlerFactory , queryInvoker , graphQLObjectMapper , invocationInputFactory .create (graphQLObjectMapper .readBatchedGraphQLRequest (inputStream ), request , response ), response );
211220 } else {
212221 query (queryInvoker , graphQLObjectMapper , invocationInputFactory .create (graphQLObjectMapper .readGraphQLRequest (inputStream ), request , response ), response );
213222 }
@@ -364,21 +373,13 @@ private void query(GraphQLQueryInvoker queryInvoker, GraphQLObjectMapper graphQL
364373 }
365374 }
366375
367- private void queryBatched (GraphQLQueryInvoker queryInvoker , GraphQLObjectMapper graphQLObjectMapper , GraphQLBatchedInvocationInput invocationInput , HttpServletResponse resp ) throws Exception {
376+ private void queryBatched (GraphQLBatchExecutionHandlerFactory batchInputHandlerFactory , GraphQLQueryInvoker queryInvoker , GraphQLObjectMapper graphQLObjectMapper , GraphQLBatchedInvocationInput invocationInput , HttpServletResponse resp ) throws Exception {
368377 resp .setContentType (APPLICATION_JSON_UTF8 );
369378 resp .setStatus (STATUS_OK );
370379
371380 Writer respWriter = resp .getWriter ();
372- respWriter .write ('[' );
373-
374- queryInvoker .query (invocationInput , (result , hasNext ) -> {
375- respWriter .write (graphQLObjectMapper .serializeResultAsJson (result ));
376- if (hasNext ) {
377- respWriter .write (',' );
378- }
379- });
380381
381- respWriter . write ( ']' );
382+ queryInvoker . query ( invocationInput , batchInputHandlerFactory . getBatchHandler ( respWriter , graphQLObjectMapper ) );
382383 }
383384
384385 private <R > List <R > runListeners (Function <? super GraphQLServletListener , R > action ) {
0 commit comments