2626
2727import java .util .List ;
2828import java .util .Map ;
29+ import java .util .concurrent .CompletableFuture ;
2930
3031import static graphql .Assert .assertNotNull ;
3132
@@ -49,7 +50,6 @@ public class GraphQL {
4950 * A GraphQL object ready to execute queries
5051 *
5152 * @param graphQLSchema the schema to use
52- *
5353 * @deprecated use the {@link #newGraphQL(GraphQLSchema)} builder instead. This will be removed in a future version.
5454 */
5555 @ Internal
@@ -63,7 +63,6 @@ public GraphQL(GraphQLSchema graphQLSchema) {
6363 *
6464 * @param graphQLSchema the schema to use
6565 * @param queryStrategy the query execution strategy to use
66- *
6766 * @deprecated use the {@link #newGraphQL(GraphQLSchema)} builder instead. This will be removed in a future version.
6867 */
6968 @ Internal
@@ -78,7 +77,6 @@ public GraphQL(GraphQLSchema graphQLSchema, ExecutionStrategy queryStrategy) {
7877 * @param graphQLSchema the schema to use
7978 * @param queryStrategy the query execution strategy to use
8079 * @param mutationStrategy the mutation execution strategy to use
81- *
8280 * @deprecated use the {@link #newGraphQL(GraphQLSchema)} builder instead. This will be removed in a future version.
8381 */
8482 @ Internal
@@ -93,7 +91,6 @@ public GraphQL(GraphQLSchema graphQLSchema, ExecutionStrategy queryStrategy, Exe
9391 * @param queryStrategy the query execution strategy to use
9492 * @param mutationStrategy the mutation execution strategy to use
9593 * @param subscriptionStrategy the subscription execution strategy to use
96- *
9794 * @deprecated use the {@link #newGraphQL(GraphQLSchema)} builder instead. This will be removed in a future version.
9895 */
9996 @ Internal
@@ -115,7 +112,6 @@ private GraphQL(GraphQLSchema graphQLSchema, ExecutionStrategy queryStrategy, Ex
115112 * Helps you build a GraphQL object ready to execute queries
116113 *
117114 * @param graphQLSchema the schema to use
118- *
119115 * @return a builder of GraphQL objects
120116 */
121117 public static Builder newGraphQL (GraphQLSchema graphQLSchema ) {
@@ -183,9 +179,7 @@ public GraphQL build() {
183179
184180 /**
185181 * @param query the query/mutation/subscription
186- *
187182 * @return result including errors
188- *
189183 * @deprecated Use {@link #execute(ExecutionInput)}
190184 */
191185 @ Deprecated
@@ -201,9 +195,7 @@ public ExecutionResult execute(String query) {
201195 *
202196 * @param query the query/mutation/subscription
203197 * @param context custom object provided to each {@link graphql.schema.DataFetcher}
204- *
205198 * @return result including errors
206- *
207199 * @deprecated Use {@link #execute(ExecutionInput)}
208200 */
209201 @ Deprecated
@@ -222,9 +214,7 @@ public ExecutionResult execute(String query, Object context) {
222214 * @param query the query/mutation/subscription
223215 * @param operationName the name of the operation to execute
224216 * @param context custom object provided to each {@link graphql.schema.DataFetcher}
225- *
226217 * @return result including errors
227- *
228218 * @deprecated Use {@link #execute(ExecutionInput)}
229219 */
230220 @ Deprecated
@@ -244,9 +234,7 @@ public ExecutionResult execute(String query, String operationName, Object contex
244234 * @param query the query/mutation/subscription
245235 * @param context custom object provided to each {@link graphql.schema.DataFetcher}
246236 * @param variables variable values uses as argument
247- *
248237 * @return result including errors
249- *
250238 * @deprecated Use {@link #execute(ExecutionInput)}
251239 */
252240 @ Deprecated
@@ -267,9 +255,7 @@ public ExecutionResult execute(String query, Object context, Map<String, Object>
267255 * @param operationName name of the operation to execute
268256 * @param context custom object provided to each {@link graphql.schema.DataFetcher}
269257 * @param variables variable values uses as argument
270- *
271258 * @return result including errors
272- *
273259 * @deprecated Use {@link #execute(ExecutionInput)}
274260 */
275261 @ Deprecated
@@ -285,25 +271,34 @@ public ExecutionResult execute(String query, String operationName, Object contex
285271 }
286272
287273 /**
288- * @param executionInput {@link ExecutionInput}
274+ * This will return a promise (aka {@link CompletableFuture}) to provide a {@link ExecutionResult}
275+ * which is the result of executing the provided query.
289276 *
290- * @return result including errors
277+ * @param executionInput {@link ExecutionInput}
278+ * @return a promise to an execution result
291279 */
292- public ExecutionResult execute (ExecutionInput executionInput ) {
280+ public CompletableFuture < ExecutionResult > executeAsync (ExecutionInput executionInput ) {
293281 log .debug ("Executing request. operation name: {}. query: {}. variables {} " , executionInput .getOperationName (), executionInput .getQuery (), executionInput .getVariables ());
294282
295283 InstrumentationContext <ExecutionResult > executionInstrumentation = instrumentation .beginExecution (new InstrumentationExecutionParameters (executionInput ));
296- final ExecutionResult executionResult = parseValidateAndExecute (executionInput );
297- executionInstrumentation .onEnd (executionResult );
298-
284+ final CompletableFuture <ExecutionResult > executionResult = parseValidateAndExecute (executionInput );
285+ executionResult .thenAccept (executionInstrumentation ::onEnd );
299286 return executionResult ;
300287 }
301288
302- private ExecutionResult parseValidateAndExecute (ExecutionInput executionInput ) {
289+ /**
290+ * @param executionInput {@link ExecutionInput}
291+ * @return result including errors
292+ */
293+ public ExecutionResult execute (ExecutionInput executionInput ) {
294+ return executeAsync (executionInput ).join ();
295+ }
296+
297+ private CompletableFuture <ExecutionResult > parseValidateAndExecute (ExecutionInput executionInput ) {
303298 PreparsedDocumentEntry preparsedDoc = preparsedDocumentProvider .get (executionInput .getQuery (), query -> parseAndValidate (executionInput ));
304299
305300 if (preparsedDoc .hasErrors ()) {
306- return new ExecutionResultImpl (preparsedDoc .getErrors ());
301+ return CompletableFuture . completedFuture ( new ExecutionResultImpl (preparsedDoc .getErrors () ));
307302 }
308303
309304 return execute (executionInput , preparsedDoc .getDocument ());
@@ -351,7 +346,7 @@ private List<ValidationError> validate(ExecutionInput executionInput, Document d
351346 return validationErrors ;
352347 }
353348
354- private ExecutionResult execute (ExecutionInput executionInput , Document document ) {
349+ private CompletableFuture < ExecutionResult > execute (ExecutionInput executionInput , Document document ) {
355350 String query = executionInput .getQuery ();
356351 String operationName = executionInput .getOperationName ();
357352 Object context = executionInput .getContext ();
0 commit comments