11package graphql .servlet ;
22
33import graphql .schema .GraphQLSchema ;
4+ import graphql .servlet .internal .GraphQLThreadFactory ;
45
56import java .util .ArrayList ;
67import java .util .List ;
7- import java .util .Objects ;
8+ import java .util .concurrent .Executor ;
9+ import java .util .concurrent .Executors ;
810
911public class GraphQLConfiguration {
1012
@@ -13,6 +15,7 @@ public class GraphQLConfiguration {
1315 private GraphQLObjectMapper objectMapper ;
1416 private List <GraphQLServletListener > listeners ;
1517 private boolean asyncServletModeEnabled ;
18+ private Executor asyncExecutor ;
1619 private long subscriptionTimeout ;
1720
1821 public static GraphQLConfiguration .Builder with (GraphQLSchema schema ) {
@@ -27,12 +30,13 @@ public static GraphQLConfiguration.Builder with(GraphQLInvocationInputFactory in
2730 return new Builder (invocationInputFactory );
2831 }
2932
30- private GraphQLConfiguration (GraphQLInvocationInputFactory invocationInputFactory , GraphQLQueryInvoker queryInvoker , GraphQLObjectMapper objectMapper , List <GraphQLServletListener > listeners , boolean asyncServletModeEnabled , long subscriptionTimeout ) {
33+ private GraphQLConfiguration (GraphQLInvocationInputFactory invocationInputFactory , GraphQLQueryInvoker queryInvoker , GraphQLObjectMapper objectMapper , List <GraphQLServletListener > listeners , boolean asyncServletModeEnabled , Executor asyncExecutor , long subscriptionTimeout ) {
3134 this .invocationInputFactory = invocationInputFactory ;
3235 this .queryInvoker = queryInvoker ;
3336 this .objectMapper = objectMapper ;
3437 this .listeners = listeners ;
3538 this .asyncServletModeEnabled = asyncServletModeEnabled ;
39+ this .asyncExecutor = asyncExecutor ;
3640 this .subscriptionTimeout = subscriptionTimeout ;
3741 }
3842
@@ -56,6 +60,10 @@ public boolean isAsyncServletModeEnabled() {
5660 return asyncServletModeEnabled ;
5761 }
5862
63+ public Executor getAsyncExecutor () {
64+ return asyncExecutor ;
65+ }
66+
5967 public void add (GraphQLServletListener listener ) {
6068 listeners .add (listener );
6169 }
@@ -76,6 +84,7 @@ public static class Builder {
7684 private GraphQLObjectMapper objectMapper = GraphQLObjectMapper .newBuilder ().build ();
7785 private List <GraphQLServletListener > listeners = new ArrayList <>();
7886 private boolean asyncServletModeEnabled = false ;
87+ private Executor asyncExecutor = Executors .newCachedThreadPool (new GraphQLThreadFactory ());
7988 private long subscriptionTimeout = 0 ;
8089
8190 private Builder (GraphQLInvocationInputFactory .Builder invocationInputFactoryBuilder ) {
@@ -112,6 +121,13 @@ public Builder with(boolean asyncServletModeEnabled) {
112121 return this ;
113122 }
114123
124+ public Builder with (Executor asyncExecutor ) {
125+ if (asyncExecutor != null ) {
126+ this .asyncExecutor = asyncExecutor ;
127+ }
128+ return this ;
129+ }
130+
115131 public Builder with (GraphQLContextBuilder contextBuilder ) {
116132 this .invocationInputFactoryBuilder .withGraphQLContextBuilder (contextBuilder );
117133 return this ;
@@ -134,6 +150,7 @@ public GraphQLConfiguration build() {
134150 objectMapper ,
135151 listeners ,
136152 asyncServletModeEnabled ,
153+ asyncExecutor ,
137154 subscriptionTimeout
138155 );
139156 }
0 commit comments