Skip to content

Commit 240f81b

Browse files
committed
Renamed handler/factory to match intent
1 parent 4fb82ff commit 240f81b

13 files changed

+60
-65
lines changed

src/main/java/graphql/servlet/AbstractGraphQLHttpServlet.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public abstract class AbstractGraphQLHttpServlet extends HttpServlet implements
7777
* @deprecated override {@link #getConfiguration()} instead
7878
*/
7979
@Deprecated
80-
protected abstract GraphQLExecutionResultHandlerFactory getBatchInputHandler();
80+
protected abstract GraphQLBatchExecutionHandlerFactory getBatchExecutionHandlerFactory();
8181

8282
/**
8383
* @deprecated override {@link #getConfiguration()} instead
@@ -91,7 +91,7 @@ protected GraphQLConfiguration getConfiguration() {
9191
.with(getGraphQLObjectMapper())
9292
.with(isAsyncServletMode())
9393
.with(listeners)
94-
.with(getBatchInputHandler())
94+
.with(getBatchExecutionHandlerFactory())
9595
.build();
9696
}
9797

@@ -120,7 +120,7 @@ public void init(ServletConfig servletConfig) {
120120
GraphQLInvocationInputFactory invocationInputFactory = configuration.getInvocationInputFactory();
121121
GraphQLObjectMapper graphQLObjectMapper = configuration.getObjectMapper();
122122
GraphQLQueryInvoker queryInvoker = configuration.getQueryInvoker();
123-
GraphQLExecutionResultHandlerFactory batchInputHandlerFactory = configuration.getBatchInputHandlerFactory();
123+
GraphQLBatchExecutionHandlerFactory batchExecutionHandlerFactory = configuration.getBatchExecutionHandlerFactory();
124124

125125
String path = request.getPathInfo();
126126
if (path == null) {
@@ -133,7 +133,7 @@ public void init(ServletConfig servletConfig) {
133133
if (query != null) {
134134

135135
if (isBatchedQuery(query)) {
136-
queryBatched(batchInputHandlerFactory, queryInvoker, graphQLObjectMapper, invocationInputFactory.createReadOnly(graphQLObjectMapper.readBatchedGraphQLRequest(query), request, response), response);
136+
queryBatched(batchExecutionHandlerFactory, queryInvoker, graphQLObjectMapper, invocationInputFactory.createReadOnly(graphQLObjectMapper.readBatchedGraphQLRequest(query), request, response), response);
137137
} else {
138138
final Map<String, Object> variables = new HashMap<>();
139139
if (request.getParameter("variables") != null) {
@@ -155,7 +155,7 @@ public void init(ServletConfig servletConfig) {
155155
GraphQLInvocationInputFactory invocationInputFactory = configuration.getInvocationInputFactory();
156156
GraphQLObjectMapper graphQLObjectMapper = configuration.getObjectMapper();
157157
GraphQLQueryInvoker queryInvoker = configuration.getQueryInvoker();
158-
GraphQLExecutionResultHandlerFactory batchInputHandlerFactory = configuration.getBatchInputHandlerFactory();
158+
GraphQLBatchExecutionHandlerFactory batchExecutionHandlerFactory = configuration.getBatchExecutionHandlerFactory();
159159

160160
try {
161161
if (APPLICATION_GRAPHQL.equals(request.getContentType())) {
@@ -190,7 +190,7 @@ public void init(ServletConfig servletConfig) {
190190
GraphQLBatchedInvocationInput invocationInput =
191191
invocationInputFactory.create(graphQLRequests, request, response);
192192
invocationInput.getContext().setParts(fileItems);
193-
queryBatched(batchInputHandlerFactory, queryInvoker, graphQLObjectMapper, invocationInput, response);
193+
queryBatched(batchExecutionHandlerFactory, queryInvoker, graphQLObjectMapper, invocationInput, response);
194194
return;
195195
} else {
196196
GraphQLRequest graphQLRequest;
@@ -216,7 +216,7 @@ public void init(ServletConfig servletConfig) {
216216
InputStream inputStream = asMarkableInputStream(request.getInputStream());
217217

218218
if (isBatchedQuery(inputStream)) {
219-
queryBatched(batchInputHandlerFactory, queryInvoker, graphQLObjectMapper, invocationInputFactory.create(graphQLObjectMapper.readBatchedGraphQLRequest(inputStream), request, response), response);
219+
queryBatched(batchExecutionHandlerFactory, queryInvoker, graphQLObjectMapper, invocationInputFactory.create(graphQLObjectMapper.readBatchedGraphQLRequest(inputStream), request, response), response);
220220
} else {
221221
query(queryInvoker, graphQLObjectMapper, invocationInputFactory.create(graphQLObjectMapper.readGraphQLRequest(inputStream), request, response), response);
222222
}
@@ -373,7 +373,7 @@ private void query(GraphQLQueryInvoker queryInvoker, GraphQLObjectMapper graphQL
373373
}
374374
}
375375

376-
private void queryBatched(GraphQLExecutionResultHandlerFactory batchInputHandlerFactory, 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 {
377377
resp.setContentType(APPLICATION_JSON_UTF8);
378378
resp.setStatus(STATUS_OK);
379379

src/main/java/graphql/servlet/ExecutionResultHandler.java renamed to src/main/java/graphql/servlet/BatchExecutionHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/**
99
* @author Andrew Potter
1010
*/
11-
public interface ExecutionResultHandler {
11+
public interface BatchExecutionHandler {
1212
/**
1313
* Allows separating the logic of handling batch queries from how each individual query is resolved.
1414
* @param batchedInvocationInput the batch query input

src/main/java/graphql/servlet/DefaultGraphQLExecutionResultHandlerFactory.java renamed to src/main/java/graphql/servlet/DefaultGraphQLBatchExecutionHandlerFactory.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@
88
import java.util.Iterator;
99
import java.util.function.BiFunction;
1010

11-
public class DefaultGraphQLExecutionResultHandlerFactory implements GraphQLExecutionResultHandlerFactory {
11+
public class DefaultGraphQLBatchExecutionHandlerFactory implements GraphQLBatchExecutionHandlerFactory {
1212
@Override
13-
public ExecutionResultHandler getBatchHandler(Writer respWriter, GraphQLObjectMapper graphQLObjectMapper) {
14-
return new DefaultGraphQLExecutionResultHandler(respWriter, graphQLObjectMapper);
13+
public BatchExecutionHandler getBatchHandler(Writer respWriter, GraphQLObjectMapper graphQLObjectMapper) {
14+
return new DefaultGraphQLBatchExecutionHandler(respWriter, graphQLObjectMapper);
1515
}
1616

17-
private class DefaultGraphQLExecutionResultHandler implements ExecutionResultHandler {
17+
private class DefaultGraphQLBatchExecutionHandler implements BatchExecutionHandler {
1818

1919
private final Writer respWriter;
2020

2121
private final GraphQLObjectMapper graphQLObjectMapper;
2222

23-
private DefaultGraphQLExecutionResultHandler(Writer respWriter, GraphQLObjectMapper graphQLObjectMapper) {
23+
private DefaultGraphQLBatchExecutionHandler(Writer respWriter, GraphQLObjectMapper graphQLObjectMapper) {
2424
this.respWriter = respWriter;
2525
this.graphQLObjectMapper = graphQLObjectMapper;
2626
}

src/main/java/graphql/servlet/DefaultGraphQLServlet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ protected GraphQLObjectMapper getGraphQLObjectMapper() {
2626
}
2727

2828
@Override
29-
protected GraphQLExecutionResultHandlerFactory getBatchInputHandler() {
29+
protected GraphQLBatchExecutionHandlerFactory getBatchExecutionHandlerFactory() {
3030
return null;
3131
}
3232

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package graphql.servlet;
2+
3+
import java.io.Writer;
4+
5+
/**
6+
* Interface to allow customization of how batched queries are handled.
7+
*/
8+
public interface GraphQLBatchExecutionHandlerFactory {
9+
/**
10+
* Produces an BatchExecutionHandler instance for a specific response. Can maintain state across each request within a batch.
11+
* @param respWriter to send the response back
12+
* @param graphQLObjectMapper to serialize results.
13+
* @return a handler instance
14+
*/
15+
BatchExecutionHandler getBatchHandler(Writer respWriter, GraphQLObjectMapper graphQLObjectMapper);
16+
}

src/main/java/graphql/servlet/GraphQLConfiguration.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class GraphQLConfiguration {
1313
private GraphQLInvocationInputFactory invocationInputFactory;
1414
private GraphQLQueryInvoker queryInvoker;
1515
private GraphQLObjectMapper objectMapper;
16-
private GraphQLExecutionResultHandlerFactory batchInputHandlerFactory;
16+
private GraphQLBatchExecutionHandlerFactory batchExecutionHandlerFactory;
1717
private List<GraphQLServletListener> listeners;
1818
private boolean asyncServletModeEnabled;
1919
private Executor asyncExecutor;
@@ -31,11 +31,11 @@ public static GraphQLConfiguration.Builder with(GraphQLInvocationInputFactory in
3131
return new Builder(invocationInputFactory);
3232
}
3333

34-
private GraphQLConfiguration(GraphQLInvocationInputFactory invocationInputFactory, GraphQLQueryInvoker queryInvoker, GraphQLObjectMapper objectMapper, GraphQLExecutionResultHandlerFactory batchInputHandlerFactory, List<GraphQLServletListener> listeners, boolean asyncServletModeEnabled, Executor asyncExecutor, long subscriptionTimeout) {
34+
private GraphQLConfiguration(GraphQLInvocationInputFactory invocationInputFactory, GraphQLQueryInvoker queryInvoker, GraphQLObjectMapper objectMapper, GraphQLBatchExecutionHandlerFactory batchExecutionHandlerFactory, List<GraphQLServletListener> listeners, boolean asyncServletModeEnabled, Executor asyncExecutor, long subscriptionTimeout) {
3535
this.invocationInputFactory = invocationInputFactory;
3636
this.queryInvoker = queryInvoker;
3737
this.objectMapper = objectMapper;
38-
this.batchInputHandlerFactory = batchInputHandlerFactory;
38+
this.batchExecutionHandlerFactory = batchExecutionHandlerFactory;
3939
this.listeners = listeners;
4040
this.asyncServletModeEnabled = asyncServletModeEnabled;
4141
this.asyncExecutor = asyncExecutor;
@@ -54,8 +54,8 @@ public GraphQLObjectMapper getObjectMapper() {
5454
return objectMapper;
5555
}
5656

57-
public GraphQLExecutionResultHandlerFactory getBatchInputHandlerFactory() {
58-
return batchInputHandlerFactory;
57+
public GraphQLBatchExecutionHandlerFactory getBatchExecutionHandlerFactory() {
58+
return batchExecutionHandlerFactory;
5959
}
6060

6161
public List<GraphQLServletListener> getListeners() {
@@ -88,7 +88,7 @@ public static class Builder {
8888
private GraphQLInvocationInputFactory invocationInputFactory;
8989
private GraphQLQueryInvoker queryInvoker = GraphQLQueryInvoker.newBuilder().build();
9090
private GraphQLObjectMapper objectMapper = GraphQLObjectMapper.newBuilder().build();
91-
private GraphQLExecutionResultHandlerFactory batchInputHandler = new DefaultGraphQLExecutionResultHandlerFactory();
91+
private GraphQLBatchExecutionHandlerFactory graphQLBatchExecutionHandlerFactory = new DefaultGraphQLBatchExecutionHandlerFactory();
9292
private List<GraphQLServletListener> listeners = new ArrayList<>();
9393
private boolean asyncServletModeEnabled = false;
9494
private Executor asyncExecutor = Executors.newCachedThreadPool(new GraphQLThreadFactory());
@@ -116,9 +116,9 @@ public Builder with(GraphQLObjectMapper objectMapper) {
116116
return this;
117117
}
118118

119-
public Builder with(GraphQLExecutionResultHandlerFactory batchInputHandlerFactory) {
120-
if (batchInputHandlerFactory != null) {
121-
this.batchInputHandler = batchInputHandlerFactory;
119+
public Builder with(GraphQLBatchExecutionHandlerFactory batchExecutionHandlerFactory) {
120+
if (batchExecutionHandlerFactory != null) {
121+
this.graphQLBatchExecutionHandlerFactory = batchExecutionHandlerFactory;
122122
}
123123
return this;
124124
}
@@ -162,7 +162,7 @@ public GraphQLConfiguration build() {
162162
this.invocationInputFactory != null ? this.invocationInputFactory : invocationInputFactoryBuilder.build(),
163163
queryInvoker,
164164
objectMapper,
165-
batchInputHandler,
165+
graphQLBatchExecutionHandlerFactory,
166166
listeners,
167167
asyncServletModeEnabled,
168168
asyncExecutor,

src/main/java/graphql/servlet/GraphQLExecutionResultHandlerFactory.java

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/main/java/graphql/servlet/GraphQLHttpServlet.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
import graphql.schema.GraphQLSchema;
44

5-
import java.util.ArrayList;
6-
import java.util.List;
7-
import java.util.Objects;
8-
95
/**
106
* @author Michiel Oliemans
117
*/
@@ -38,7 +34,7 @@ protected GraphQLObjectMapper getGraphQLObjectMapper() {
3834
}
3935

4036
@Override
41-
protected GraphQLExecutionResultHandlerFactory getBatchInputHandler() {
37+
protected GraphQLBatchExecutionHandlerFactory getBatchExecutionHandlerFactory() {
4238
throw new UnsupportedOperationException();
4339
}
4440

src/main/java/graphql/servlet/GraphQLQueryInvoker.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import java.security.AccessController;
1717
import java.security.PrivilegedAction;
1818
import java.util.ArrayList;
19-
import java.util.Iterator;
2019
import java.util.List;
2120
import java.util.function.Supplier;
2221

@@ -41,8 +40,8 @@ public ExecutionResult query(GraphQLSingleInvocationInput singleInvocationInput)
4140
return query(singleInvocationInput, singleInvocationInput.getExecutionInput());
4241
}
4342

44-
public void query(GraphQLBatchedInvocationInput batchedInvocationInput, ExecutionResultHandler executionResultHandler) {
45-
executionResultHandler.handleBatch(batchedInvocationInput, this::query);
43+
public void query(GraphQLBatchedInvocationInput batchedInvocationInput, BatchExecutionHandler batchExecutionHandler) {
44+
batchExecutionHandler.handleBatch(batchedInvocationInput, this::query);
4645
}
4746

4847
private GraphQL newGraphQL(GraphQLSchema schema, Object context) {

src/main/java/graphql/servlet/OsgiGraphQLHttpServlet.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class OsgiGraphQLHttpServlet extends AbstractGraphQLHttpServlet {
4646
private InstrumentationProvider instrumentationProvider = new NoOpInstrumentationProvider();
4747
private GraphQLErrorHandler errorHandler = new DefaultGraphQLErrorHandler();
4848
private PreparsedDocumentProvider preparsedDocumentProvider = NoOpPreparsedDocumentProvider.INSTANCE;
49-
private GraphQLExecutionResultHandlerFactory executionResultHandlerFactory = new DefaultGraphQLExecutionResultHandlerFactory();
49+
private GraphQLBatchExecutionHandlerFactory executionResultHandlerFactory = new DefaultGraphQLBatchExecutionHandlerFactory();
5050

5151
private GraphQLSchemaProvider schemaProvider;
5252

@@ -86,7 +86,7 @@ protected GraphQLObjectMapper getGraphQLObjectMapper() {
8686
}
8787

8888
@Override
89-
protected GraphQLExecutionResultHandlerFactory getBatchInputHandler() {
89+
protected GraphQLBatchExecutionHandlerFactory getBatchExecutionHandlerFactory() {
9090
return executionResultHandlerFactory;
9191
}
9292

0 commit comments

Comments
 (0)