2727import java .util .List ;
2828import java .util .Map ;
2929import java .util .concurrent .CompletableFuture ;
30+ import java .util .function .UnaryOperator ;
3031
3132import static graphql .Assert .assertNotNull ;
3233
@@ -50,6 +51,7 @@ public class GraphQL {
5051 * A GraphQL object ready to execute queries
5152 *
5253 * @param graphQLSchema the schema to use
54+ *
5355 * @deprecated use the {@link #newGraphQL(GraphQLSchema)} builder instead. This will be removed in a future version.
5456 */
5557 @ Internal
@@ -63,6 +65,7 @@ public GraphQL(GraphQLSchema graphQLSchema) {
6365 *
6466 * @param graphQLSchema the schema to use
6567 * @param queryStrategy the query execution strategy to use
68+ *
6669 * @deprecated use the {@link #newGraphQL(GraphQLSchema)} builder instead. This will be removed in a future version.
6770 */
6871 @ Internal
@@ -77,6 +80,7 @@ public GraphQL(GraphQLSchema graphQLSchema, ExecutionStrategy queryStrategy) {
7780 * @param graphQLSchema the schema to use
7881 * @param queryStrategy the query execution strategy to use
7982 * @param mutationStrategy the mutation execution strategy to use
83+ *
8084 * @deprecated use the {@link #newGraphQL(GraphQLSchema)} builder instead. This will be removed in a future version.
8185 */
8286 @ Internal
@@ -91,6 +95,7 @@ public GraphQL(GraphQLSchema graphQLSchema, ExecutionStrategy queryStrategy, Exe
9195 * @param queryStrategy the query execution strategy to use
9296 * @param mutationStrategy the mutation execution strategy to use
9397 * @param subscriptionStrategy the subscription execution strategy to use
98+ *
9499 * @deprecated use the {@link #newGraphQL(GraphQLSchema)} builder instead. This will be removed in a future version.
95100 */
96101 @ Internal
@@ -112,6 +117,7 @@ private GraphQL(GraphQLSchema graphQLSchema, ExecutionStrategy queryStrategy, Ex
112117 * Helps you build a GraphQL object ready to execute queries
113118 *
114119 * @param graphQLSchema the schema to use
120+ *
115121 * @return a builder of GraphQL objects
116122 */
117123 public static Builder newGraphQL (GraphQLSchema graphQLSchema ) {
@@ -178,11 +184,12 @@ public GraphQL build() {
178184 }
179185
180186 /**
187+ * Executes the specified graphql query/mutation/subscription
188+ *
181189 * @param query the query/mutation/subscription
182- * @return result including errors
183- * @deprecated Use {@link #execute(ExecutionInput)}
190+ *
191+ * @return an {@link ExecutionResult} which can include errors
184192 */
185- @ Deprecated
186193 public ExecutionResult execute (String query ) {
187194 ExecutionInput executionInput = ExecutionInput .newExecutionInput ()
188195 .query (query )
@@ -195,7 +202,9 @@ public ExecutionResult execute(String query) {
195202 *
196203 * @param query the query/mutation/subscription
197204 * @param context custom object provided to each {@link graphql.schema.DataFetcher}
198- * @return result including errors
205+ *
206+ * @return an {@link ExecutionResult} which can include errors
207+ *
199208 * @deprecated Use {@link #execute(ExecutionInput)}
200209 */
201210 @ Deprecated
@@ -214,7 +223,9 @@ public ExecutionResult execute(String query, Object context) {
214223 * @param query the query/mutation/subscription
215224 * @param operationName the name of the operation to execute
216225 * @param context custom object provided to each {@link graphql.schema.DataFetcher}
217- * @return result including errors
226+ *
227+ * @return an {@link ExecutionResult} which can include errors
228+ *
218229 * @deprecated Use {@link #execute(ExecutionInput)}
219230 */
220231 @ Deprecated
@@ -234,7 +245,9 @@ public ExecutionResult execute(String query, String operationName, Object contex
234245 * @param query the query/mutation/subscription
235246 * @param context custom object provided to each {@link graphql.schema.DataFetcher}
236247 * @param variables variable values uses as argument
237- * @return result including errors
248+ *
249+ * @return an {@link ExecutionResult} which can include errors
250+ *
238251 * @deprecated Use {@link #execute(ExecutionInput)}
239252 */
240253 @ Deprecated
@@ -255,7 +268,9 @@ public ExecutionResult execute(String query, Object context, Map<String, Object>
255268 * @param operationName name of the operation to execute
256269 * @param context custom object provided to each {@link graphql.schema.DataFetcher}
257270 * @param variables variable values uses as argument
258- * @return result including errors
271+ *
272+ * @return an {@link ExecutionResult} which can include errors
273+ *
259274 * @deprecated Use {@link #execute(ExecutionInput)}
260275 */
261276 @ Deprecated
@@ -271,11 +286,91 @@ public ExecutionResult execute(String query, String operationName, Object contex
271286 }
272287
273288 /**
289+ * Executes the graphql query using the provided input object builder
290+ *
291+ * @param executionInputBuilder {@link ExecutionInput.Builder}
292+ *
293+ * @return an {@link ExecutionResult} which can include errors
294+ */
295+ public ExecutionResult execute (ExecutionInput .Builder executionInputBuilder ) {
296+ return execute (executionInputBuilder .build ());
297+ }
298+
299+ /**
300+ * Executes the graphql query using calling the builder function and giving it a new builder.
301+ * <p>
302+ * This allows a lambda style like :
303+ *
304+ * <pre>
305+ * {@code
306+ * ExecutionResult result = graphql.execute(input -> input.query("{hello}").root(startingObj).context(contextObj));
307+ * }
308+ * </pre>
309+ *
310+ * @param builderFunction a function that is given a {@link ExecutionInput.Builder}
311+ *
312+ * @return an {@link ExecutionResult} which can include errors
313+ */
314+ public ExecutionResult execute (UnaryOperator <ExecutionInput .Builder > builderFunction ) {
315+ return execute (builderFunction .apply (ExecutionInput .newExecutionInput ()).build ());
316+ }
317+
318+ /**
319+ * Executes the graphql query using the provided input object
320+ *
321+ * @param executionInput {@link ExecutionInput}
322+ *
323+ * @return an {@link ExecutionResult} which can include errors
324+ */
325+ public ExecutionResult execute (ExecutionInput executionInput ) {
326+ return executeAsync (executionInput ).join ();
327+ }
328+
329+ /**
330+ * Executes the graphql query using the provided input object builder
331+ *
332+ * This will return a promise (aka {@link CompletableFuture}) to provide a {@link ExecutionResult}
333+ * which is the result of executing the provided query.
334+ *
335+ * @param executionInputBuilder {@link ExecutionInput.Builder}
336+ *
337+ * @return a promise to an {@link ExecutionResult} which can include errors
338+ */
339+ public CompletableFuture <ExecutionResult > executeAsync (ExecutionInput .Builder executionInputBuilder ) {
340+ return executeAsync (executionInputBuilder .build ());
341+ }
342+
343+ /**
344+ * Executes the graphql query using the provided input object builder
345+ *
346+ * This will return a promise (aka {@link CompletableFuture}) to provide a {@link ExecutionResult}
347+ * which is the result of executing the provided query.
348+ * <p>
349+ * This allows a lambda style like :
350+ *
351+ * <pre>
352+ * {@code
353+ * ExecutionResult result = graphql.execute(input -> input.query("{hello}").root(startingObj).context(contextObj));
354+ * }
355+ * </pre>
356+ *
357+ * @param builderFunction a function that is given a {@link ExecutionInput.Builder}
358+ *
359+ * @return a promise to an {@link ExecutionResult} which can include errors
360+ */
361+ public CompletableFuture <ExecutionResult > executeAsync (UnaryOperator <ExecutionInput .Builder > builderFunction ) {
362+ return executeAsync (builderFunction .apply (ExecutionInput .newExecutionInput ()).build ());
363+ }
364+
365+ /**
366+ * Executes the graphql query using the provided input object
367+ *
274368 * This will return a promise (aka {@link CompletableFuture}) to provide a {@link ExecutionResult}
275369 * which is the result of executing the provided query.
276370 *
277371 * @param executionInput {@link ExecutionInput}
278- * @return a promise to an execution result
372+ *
373+ * @return a promise to an {@link ExecutionResult} which can include errors
279374 */
280375 public CompletableFuture <ExecutionResult > executeAsync (ExecutionInput executionInput ) {
281376 log .debug ("Executing request. operation name: {}. query: {}. variables {} " , executionInput .getOperationName (), executionInput .getQuery (), executionInput .getVariables ());
@@ -286,13 +381,6 @@ public CompletableFuture<ExecutionResult> executeAsync(ExecutionInput executionI
286381 return executionResult ;
287382 }
288383
289- /**
290- * @param executionInput {@link ExecutionInput}
291- * @return result including errors
292- */
293- public ExecutionResult execute (ExecutionInput executionInput ) {
294- return executeAsync (executionInput ).join ();
295- }
296384
297385 private CompletableFuture <ExecutionResult > parseValidateAndExecute (ExecutionInput executionInput ) {
298386 PreparsedDocumentEntry preparsedDoc = preparsedDocumentProvider .get (executionInput .getQuery (), query -> parseAndValidate (executionInput ));
0 commit comments