@@ -412,6 +412,9 @@ public CompletableFuture<ExecutionResult> executeAsync(UnaryOperator<ExecutionIn
412412 * @return a promise to an {@link ExecutionResult} which can include errors
413413 */
414414 public CompletableFuture <ExecutionResult > executeAsync (ExecutionInput executionInput ) {
415+ Profiler profiler = executionInput .isProfileExecution () ? new ProfilerImpl () : Profiler .NO_OP ;
416+ profiler .start ();
417+
415418 ExecutionInput executionInputWithId = ensureInputHasId (executionInput );
416419
417420 CompletableFuture <InstrumentationState > instrumentationStateCF = instrumentation .createStateAsync (new InstrumentationCreateStateParameters (this .graphQLSchema , executionInputWithId ));
@@ -426,7 +429,7 @@ public CompletableFuture<ExecutionResult> executeAsync(ExecutionInput executionI
426429
427430 GraphQLSchema graphQLSchema = instrumentation .instrumentSchema (this .graphQLSchema , instrumentationParameters , instrumentationState );
428431
429- CompletableFuture <ExecutionResult > executionResult = parseValidateAndExecute (instrumentedExecutionInput , graphQLSchema , instrumentationState );
432+ CompletableFuture <ExecutionResult > executionResult = parseValidateAndExecute (instrumentedExecutionInput , graphQLSchema , instrumentationState , profiler );
430433 //
431434 // finish up instrumentation
432435 executionResult = executionResult .whenComplete (completeInstrumentationCtxCF (executionInstrumentation ));
@@ -460,27 +463,27 @@ private ExecutionInput ensureInputHasId(ExecutionInput executionInput) {
460463 }
461464
462465
463- private CompletableFuture <ExecutionResult > parseValidateAndExecute (ExecutionInput executionInput , GraphQLSchema graphQLSchema , InstrumentationState instrumentationState ) {
466+ private CompletableFuture <ExecutionResult > parseValidateAndExecute (ExecutionInput executionInput , GraphQLSchema graphQLSchema , InstrumentationState instrumentationState , Profiler profiler ) {
464467 AtomicReference <ExecutionInput > executionInputRef = new AtomicReference <>(executionInput );
465468 Function <ExecutionInput , PreparsedDocumentEntry > computeFunction = transformedInput -> {
466469 // if they change the original query in the pre-parser, then we want to see it downstream from then on
467470 executionInputRef .set (transformedInput );
468- return parseAndValidate (executionInputRef , graphQLSchema , instrumentationState );
471+ return parseAndValidate (executionInputRef , graphQLSchema , instrumentationState , profiler );
469472 };
470473 CompletableFuture <PreparsedDocumentEntry > preparsedDoc = preparsedDocumentProvider .getDocumentAsync (executionInput , computeFunction );
471474 return preparsedDoc .thenCompose (preparsedDocumentEntry -> {
472475 if (preparsedDocumentEntry .hasErrors ()) {
473476 return CompletableFuture .completedFuture (new ExecutionResultImpl (preparsedDocumentEntry .getErrors ()));
474477 }
475478 try {
476- return execute (executionInputRef .get (), preparsedDocumentEntry .getDocument (), graphQLSchema , instrumentationState );
479+ return executeImpl (executionInputRef .get (), preparsedDocumentEntry .getDocument (), graphQLSchema , instrumentationState , profiler );
477480 } catch (AbortExecutionException e ) {
478481 return CompletableFuture .completedFuture (e .toExecutionResult ());
479482 }
480483 });
481484 }
482485
483- private PreparsedDocumentEntry parseAndValidate (AtomicReference <ExecutionInput > executionInputRef , GraphQLSchema graphQLSchema , InstrumentationState instrumentationState ) {
486+ private PreparsedDocumentEntry parseAndValidate (AtomicReference <ExecutionInput > executionInputRef , GraphQLSchema graphQLSchema , InstrumentationState instrumentationState , Profiler profiler ) {
484487
485488 ExecutionInput executionInput = executionInputRef .get ();
486489
@@ -533,13 +536,14 @@ private List<ValidationError> validate(ExecutionInput executionInput, Document d
533536 return validationErrors ;
534537 }
535538
536- private CompletableFuture <ExecutionResult > execute (ExecutionInput executionInput ,
537- Document document ,
538- GraphQLSchema graphQLSchema ,
539- InstrumentationState instrumentationState
539+ private CompletableFuture <ExecutionResult > executeImpl (ExecutionInput executionInput ,
540+ Document document ,
541+ GraphQLSchema graphQLSchema ,
542+ InstrumentationState instrumentationState ,
543+ Profiler profiler
540544 ) {
541545
542- Execution execution = new Execution (queryStrategy , mutationStrategy , subscriptionStrategy , instrumentation , valueUnboxer , doNotAutomaticallyDispatchDataLoader );
546+ Execution execution = new Execution (queryStrategy , mutationStrategy , subscriptionStrategy , instrumentation , valueUnboxer , doNotAutomaticallyDispatchDataLoader , profiler );
543547 ExecutionId executionId = executionInput .getExecutionId ();
544548
545549 return execution .execute (document , graphQLSchema , executionId , executionInput , instrumentationState );
0 commit comments