|
16 | 16 | import graphql.execution.instrumentation.Instrumentation; |
17 | 17 | import graphql.execution.instrumentation.InstrumentationContext; |
18 | 18 | import graphql.execution.instrumentation.InstrumentationState; |
| 19 | +import graphql.execution.instrumentation.NoContextChainedInstrumentation; |
19 | 20 | import graphql.execution.instrumentation.SimpleInstrumentation; |
20 | 21 | import graphql.execution.instrumentation.dataloader.DataLoaderDispatcherInstrumentation; |
21 | 22 | import graphql.execution.instrumentation.parameters.InstrumentationCreateStateParameters; |
|
46 | 47 | import static graphql.Assert.assertNotNull; |
47 | 48 | import static graphql.execution.ExecutionIdProvider.DEFAULT_EXECUTION_ID_PROVIDER; |
48 | 49 | import static graphql.execution.instrumentation.SimpleInstrumentationContext.completeInstrumentationCtxCF; |
| 50 | +import static graphql.execution.instrumentation.SimpleInstrumentationContext.nonNullCtx; |
49 | 51 |
|
50 | 52 | /** |
51 | 53 | * 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 |
512 | 514 | InstrumentationState instrumentationState = instrumentation.createState(new InstrumentationCreateStateParameters(this.graphQLSchema, executionInput)); |
513 | 515 |
|
514 | 516 | InstrumentationExecutionParameters inputInstrumentationParameters = new InstrumentationExecutionParameters(executionInput, this.graphQLSchema, instrumentationState); |
515 | | - executionInput = instrumentation.instrumentExecutionInput(executionInput, inputInstrumentationParameters); |
| 517 | + executionInput = instrumentation.instrumentExecutionInput(executionInput, inputInstrumentationParameters, instrumentationState); |
516 | 518 |
|
517 | 519 | CompletableFuture<ExecutionResult> beginExecutionCF = new CompletableFuture<>(); |
518 | 520 | InstrumentationExecutionParameters instrumentationParameters = new InstrumentationExecutionParameters(executionInput, this.graphQLSchema, instrumentationState); |
519 | | - InstrumentationContext<ExecutionResult> executionInstrumentation = instrumentation.beginExecution(instrumentationParameters); |
| 521 | + InstrumentationContext<ExecutionResult> executionInstrumentation = nonNullCtx(instrumentation.beginExecution(instrumentationParameters, instrumentationState)); |
520 | 522 | executionInstrumentation.onDispatched(beginExecutionCF); |
521 | 523 |
|
522 | | - GraphQLSchema graphQLSchema = instrumentation.instrumentSchema(this.graphQLSchema, instrumentationParameters); |
| 524 | + GraphQLSchema graphQLSchema = instrumentation.instrumentSchema(this.graphQLSchema, instrumentationParameters, instrumentationState); |
523 | 525 |
|
524 | 526 | CompletableFuture<ExecutionResult> executionResult = parseValidateAndExecute(executionInput, graphQLSchema, instrumentationState); |
525 | 527 | // |
526 | 528 | // finish up instrumentation |
527 | 529 | executionResult = executionResult.whenComplete(completeInstrumentationCtxCF(executionInstrumentation, beginExecutionCF)); |
528 | 530 | // |
529 | 531 | // 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)); |
531 | 533 | return executionResult; |
532 | 534 | } catch (AbortExecutionException abortException) { |
533 | 535 | return CompletableFuture.completedFuture(abortException.toExecutionResult()); |
@@ -598,32 +600,32 @@ private PreparsedDocumentEntry parseAndValidate(AtomicReference<ExecutionInput> |
598 | 600 |
|
599 | 601 | private ParseAndValidateResult parse(ExecutionInput executionInput, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState) { |
600 | 602 | InstrumentationExecutionParameters parameters = new InstrumentationExecutionParameters(executionInput, graphQLSchema, instrumentationState); |
601 | | - InstrumentationContext<Document> parseInstrumentation = instrumentation.beginParse(parameters); |
| 603 | + InstrumentationContext<Document> parseInstrumentationCtx = nonNullCtx(instrumentation.beginParse(parameters, instrumentationState)); |
602 | 604 | CompletableFuture<Document> documentCF = new CompletableFuture<>(); |
603 | | - parseInstrumentation.onDispatched(documentCF); |
| 605 | + parseInstrumentationCtx.onDispatched(documentCF); |
604 | 606 |
|
605 | 607 | ParseAndValidateResult parseResult = ParseAndValidate.parse(executionInput); |
606 | 608 | if (parseResult.isFailure()) { |
607 | | - parseInstrumentation.onCompleted(null, parseResult.getSyntaxException()); |
| 609 | + parseInstrumentationCtx.onCompleted(null, parseResult.getSyntaxException()); |
608 | 610 | return parseResult; |
609 | 611 | } else { |
610 | 612 | documentCF.complete(parseResult.getDocument()); |
611 | | - parseInstrumentation.onCompleted(parseResult.getDocument(), null); |
| 613 | + parseInstrumentationCtx.onCompleted(parseResult.getDocument(), null); |
612 | 614 |
|
613 | 615 | DocumentAndVariables documentAndVariables = parseResult.getDocumentAndVariables(); |
614 | | - documentAndVariables = instrumentation.instrumentDocumentAndVariables(documentAndVariables, parameters); |
| 616 | + documentAndVariables = instrumentation.instrumentDocumentAndVariables(documentAndVariables, parameters, instrumentationState); |
615 | 617 | return ParseAndValidateResult.newResult() |
616 | 618 | .document(documentAndVariables.getDocument()).variables(documentAndVariables.getVariables()).build(); |
617 | 619 | } |
618 | 620 | } |
619 | 621 |
|
620 | 622 | 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)); |
622 | 624 | CompletableFuture<List<ValidationError>> cf = new CompletableFuture<>(); |
623 | 625 | validationCtx.onDispatched(cf); |
624 | 626 |
|
625 | 627 | 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()); |
627 | 629 |
|
628 | 630 | validationCtx.onCompleted(validationErrors, null); |
629 | 631 | cf.complete(validationErrors); |
@@ -663,6 +665,9 @@ private static Instrumentation checkInstrumentationDefaultState(Instrumentation |
663 | 665 | if (instrumentation instanceof DataLoaderDispatcherInstrumentation) { |
664 | 666 | return instrumentation; |
665 | 667 | } |
| 668 | + if (instrumentation instanceof NoContextChainedInstrumentation) { |
| 669 | + return instrumentation; |
| 670 | + } |
666 | 671 | if (instrumentation == null) { |
667 | 672 | return new DataLoaderDispatcherInstrumentation(); |
668 | 673 | } |
|
0 commit comments