Skip to content

Commit 94d8b22

Browse files
committed
Add overloaded constructor for operationListeners.
1 parent 17792dc commit 94d8b22

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/main/java/graphql/servlet/GraphQLServlet.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,15 @@ public abstract class GraphQLServlet extends HttpServlet implements Servlet, Gra
6666
protected abstract ExecutionStrategy getExecutionStrategy();
6767
protected abstract Map<String, Object> transformVariables(GraphQLSchema schema, String query, Map<String, Object> variables);
6868

69+
private List<GraphQLOperationListener> operationListeners;
6970

70-
private List<GraphQLOperationListener> operationListeners = new ArrayList<>();
71+
public GraphQLServlet() {
72+
this(new ArrayList<>());
73+
}
74+
75+
public GraphQLServlet(List<GraphQLOperationListener> operationListeners) {
76+
this.operationListeners = new ArrayList<>(operationListeners);
77+
}
7178

7279
public void addOperationListener(GraphQLOperationListener operationListener) {
7380
operationListeners.add(operationListener);

src/main/java/graphql/servlet/SimpleGraphQLServlet.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
import javax.servlet.http.HttpServletRequest;
2121
import javax.servlet.http.HttpServletResponse;
22+
import java.util.ArrayList;
23+
import java.util.List;
2224
import java.util.Map;
2325
import java.util.Optional;
2426

@@ -28,6 +30,12 @@
2830
public class SimpleGraphQLServlet extends GraphQLServlet {
2931

3032
public SimpleGraphQLServlet(GraphQLSchema schema, ExecutionStrategy executionStrategy) {
33+
this(schema, executionStrategy, new ArrayList<>());
34+
}
35+
36+
public SimpleGraphQLServlet(GraphQLSchema schema, ExecutionStrategy executionStrategy, List<GraphQLOperationListener> operationListeners) {
37+
super(operationListeners);
38+
3139
this.schema = schema;
3240
this.readOnlySchema = new GraphQLSchema(schema.getQueryType(), null, schema.getDictionary());
3341

0 commit comments

Comments
 (0)