1616import graphql .execution .instrumentation .Instrumentation ;
1717import graphql .execution .instrumentation .InstrumentationContext ;
1818import graphql .execution .instrumentation .InstrumentationState ;
19+ import graphql .execution .instrumentation .NoContextChainedInstrumentation ;
1920import graphql .execution .instrumentation .SimpleInstrumentation ;
2021import graphql .execution .instrumentation .dataloader .DataLoaderDispatcherInstrumentation ;
2122import graphql .execution .instrumentation .parameters .InstrumentationCreateStateParameters ;
4647import static graphql .Assert .assertNotNull ;
4748import static graphql .execution .ExecutionIdProvider .DEFAULT_EXECUTION_ID_PROVIDER ;
4849import static graphql .execution .instrumentation .SimpleInstrumentationContext .completeInstrumentationCtxCF ;
50+ import static graphql .execution .instrumentation .SimpleInstrumentationContext .nonNullCtx ;
4951
5052/**
5153 * This class is where all graphql-java query execution begins. It combines the objects that are needed
@@ -512,22 +514,22 @@ public CompletableFuture<ExecutionResult> executeAsync(ExecutionInput executionI
512514 InstrumentationState instrumentationState = instrumentation .createState (new InstrumentationCreateStateParameters (this .graphQLSchema , executionInput ));
513515
514516 InstrumentationExecutionParameters inputInstrumentationParameters = new InstrumentationExecutionParameters (executionInput , this .graphQLSchema , instrumentationState );
515- executionInput = instrumentation .instrumentExecutionInput (executionInput , inputInstrumentationParameters );
517+ executionInput = instrumentation .instrumentExecutionInput (executionInput , inputInstrumentationParameters , instrumentationState );
516518
517519 CompletableFuture <ExecutionResult > beginExecutionCF = new CompletableFuture <>();
518520 InstrumentationExecutionParameters instrumentationParameters = new InstrumentationExecutionParameters (executionInput , this .graphQLSchema , instrumentationState );
519- InstrumentationContext <ExecutionResult > executionInstrumentation = instrumentation .beginExecution (instrumentationParameters );
521+ InstrumentationContext <ExecutionResult > executionInstrumentation = nonNullCtx ( instrumentation .beginExecution (instrumentationParameters , instrumentationState ) );
520522 executionInstrumentation .onDispatched (beginExecutionCF );
521523
522- GraphQLSchema graphQLSchema = instrumentation .instrumentSchema (this .graphQLSchema , instrumentationParameters );
524+ GraphQLSchema graphQLSchema = instrumentation .instrumentSchema (this .graphQLSchema , instrumentationParameters , instrumentationState );
523525
524526 CompletableFuture <ExecutionResult > executionResult = parseValidateAndExecute (executionInput , graphQLSchema , instrumentationState );
525527 //
526528 // finish up instrumentation
527529 executionResult = executionResult .whenComplete (completeInstrumentationCtxCF (executionInstrumentation , beginExecutionCF ));
528530 //
529531 // allow instrumentation to tweak the result
530- executionResult = executionResult .thenCompose (result -> instrumentation .instrumentExecutionResult (result , instrumentationParameters ));
532+ executionResult = executionResult .thenCompose (result -> instrumentation .instrumentExecutionResult (result , instrumentationParameters , instrumentationState ));
531533 return executionResult ;
532534 } catch (AbortExecutionException abortException ) {
533535 return CompletableFuture .completedFuture (abortException .toExecutionResult ());
@@ -589,7 +591,7 @@ private PreparsedDocumentEntry parseAndValidate(AtomicReference<ExecutionInput>
589591 final List <ValidationError > errors = validate (executionInput , document , graphQLSchema , instrumentationState );
590592 if (!errors .isEmpty ()) {
591593 logNotSafe .warn ("Query did not validate : '{}'" , query );
592- return new PreparsedDocumentEntry (errors );
594+ return new PreparsedDocumentEntry (document , errors );
593595 }
594596
595597 return new PreparsedDocumentEntry (document );
@@ -598,32 +600,32 @@ private PreparsedDocumentEntry parseAndValidate(AtomicReference<ExecutionInput>
598600
599601 private ParseAndValidateResult parse (ExecutionInput executionInput , GraphQLSchema graphQLSchema , InstrumentationState instrumentationState ) {
600602 InstrumentationExecutionParameters parameters = new InstrumentationExecutionParameters (executionInput , graphQLSchema , instrumentationState );
601- InstrumentationContext <Document > parseInstrumentation = instrumentation .beginParse (parameters );
603+ InstrumentationContext <Document > parseInstrumentationCtx = nonNullCtx ( instrumentation .beginParse (parameters , instrumentationState ) );
602604 CompletableFuture <Document > documentCF = new CompletableFuture <>();
603- parseInstrumentation .onDispatched (documentCF );
605+ parseInstrumentationCtx .onDispatched (documentCF );
604606
605607 ParseAndValidateResult parseResult = ParseAndValidate .parse (executionInput );
606608 if (parseResult .isFailure ()) {
607- parseInstrumentation .onCompleted (null , parseResult .getSyntaxException ());
609+ parseInstrumentationCtx .onCompleted (null , parseResult .getSyntaxException ());
608610 return parseResult ;
609611 } else {
610612 documentCF .complete (parseResult .getDocument ());
611- parseInstrumentation .onCompleted (parseResult .getDocument (), null );
613+ parseInstrumentationCtx .onCompleted (parseResult .getDocument (), null );
612614
613615 DocumentAndVariables documentAndVariables = parseResult .getDocumentAndVariables ();
614- documentAndVariables = instrumentation .instrumentDocumentAndVariables (documentAndVariables , parameters );
616+ documentAndVariables = instrumentation .instrumentDocumentAndVariables (documentAndVariables , parameters , instrumentationState );
615617 return ParseAndValidateResult .newResult ()
616618 .document (documentAndVariables .getDocument ()).variables (documentAndVariables .getVariables ()).build ();
617619 }
618620 }
619621
620622 private List <ValidationError > validate (ExecutionInput executionInput , Document document , GraphQLSchema graphQLSchema , InstrumentationState instrumentationState ) {
621- InstrumentationContext <List <ValidationError >> validationCtx = instrumentation .beginValidation (new InstrumentationValidationParameters (executionInput , document , graphQLSchema , instrumentationState ));
623+ InstrumentationContext <List <ValidationError >> validationCtx = nonNullCtx ( instrumentation .beginValidation (new InstrumentationValidationParameters (executionInput , document , graphQLSchema , instrumentationState ) , instrumentationState ));
622624 CompletableFuture <List <ValidationError >> cf = new CompletableFuture <>();
623625 validationCtx .onDispatched (cf );
624626
625627 Predicate <Class <?>> validationRulePredicate = executionInput .getGraphQLContext ().getOrDefault (ParseAndValidate .INTERNAL_VALIDATION_PREDICATE_HINT , r -> true );
626- List <ValidationError > validationErrors = ParseAndValidate .validate (graphQLSchema , document , validationRulePredicate );
628+ List <ValidationError > validationErrors = ParseAndValidate .validate (graphQLSchema , document , validationRulePredicate , executionInput . getLocale () );
627629
628630 validationCtx .onCompleted (validationErrors , null );
629631 cf .complete (validationErrors );
@@ -663,6 +665,9 @@ private static Instrumentation checkInstrumentationDefaultState(Instrumentation
663665 if (instrumentation instanceof DataLoaderDispatcherInstrumentation ) {
664666 return instrumentation ;
665667 }
668+ if (instrumentation instanceof NoContextChainedInstrumentation ) {
669+ return instrumentation ;
670+ }
666671 if (instrumentation == null ) {
667672 return new DataLoaderDispatcherInstrumentation ();
668673 }
@@ -683,4 +688,4 @@ private static Instrumentation checkInstrumentationDefaultState(Instrumentation
683688 }
684689 return new ChainedInstrumentation (instrumentationList );
685690 }
686- }
691+ }
0 commit comments