Skip to content

Commit 487fced

Browse files
committed
Allow configuring execution strategy
1 parent 15d2061 commit 487fced

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Copyright 2016 Yurii Rashkovskii
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
*/
15+
package graphql.servlet;
16+
17+
import graphql.annotations.EnhancedExecutionStrategy;
18+
import graphql.execution.ExecutionStrategy;
19+
20+
public class EnhancedExecutionStrategyProvider implements ExecutionStrategyProvider {
21+
@Override
22+
public ExecutionStrategy getExecutionStrategy() {
23+
return new EnhancedExecutionStrategy();
24+
}
25+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Copyright 2016 Yurii Rashkovskii
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
*/
15+
package graphql.servlet;
16+
17+
import graphql.execution.ExecutionStrategy;
18+
19+
public interface ExecutionStrategyProvider {
20+
ExecutionStrategy getExecutionStrategy();
21+
}

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import com.fasterxml.jackson.databind.ObjectMapper;
1818
import com.google.common.io.CharStreams;
1919
import graphql.*;
20-
import graphql.annotations.EnhancedExecutionStrategy;
2120
import graphql.schema.GraphQLFieldDefinition;
2221
import graphql.schema.GraphQLObjectType;
2322
import graphql.schema.GraphQLSchema;
@@ -118,6 +117,7 @@ public String[] getMutations() {
118117
}
119118

120119
private GraphQLContextBuilder contextBuilder = new DefaultGraphQLContextBuilder();
120+
private ExecutionStrategyProvider executionStrategyProvider = new EnhancedExecutionStrategyProvider();
121121

122122
@Reference
123123
public void setContextProvider(GraphQLContextBuilder contextBuilder) {
@@ -127,6 +127,14 @@ public void unsetContextProvider(GraphQLContextBuilder contextBuilder) {
127127
this.contextBuilder = new DefaultGraphQLContextBuilder();
128128
}
129129

130+
@Reference
131+
public void setExecutionStrategyProvider(ExecutionStrategyProvider provider) {
132+
executionStrategyProvider = provider;
133+
}
134+
public void unsetExecutionStrategyProvider(ExecutionStrategyProvider provider) {
135+
executionStrategyProvider = new EnhancedExecutionStrategyProvider();
136+
}
137+
130138
protected GraphQLContext createContext(Optional<HttpServletRequest> req, Optional<HttpServletResponse> resp) {
131139
return contextBuilder.build(req, resp);
132140
}
@@ -180,7 +188,7 @@ public Void run() {
180188
}
181189
});
182190
} else {
183-
ExecutionResult result = new GraphQL(schema, new EnhancedExecutionStrategy()).execute(query, context, variables);
191+
ExecutionResult result = new GraphQL(schema, executionStrategyProvider.getExecutionStrategy()).execute(query, context, variables);
184192
resp.setContentType("application/json");
185193
if (result.getErrors().isEmpty()) {
186194
Map<String, Object> dict = new HashMap<>();

0 commit comments

Comments
 (0)