99import graphql .execution .ExecutionId ;
1010import graphql .execution .ExecutionIdProvider ;
1111import graphql .execution .ExecutionStrategy ;
12- import graphql .execution .ResponseMapFactory ;
1312import graphql .execution .SimpleDataFetcherExceptionHandler ;
1413import graphql .execution .SubscriptionExecutionStrategy ;
1514import graphql .execution .ValueUnboxer ;
2524import graphql .execution .preparsed .PreparsedDocumentEntry ;
2625import graphql .execution .preparsed .PreparsedDocumentProvider ;
2726import graphql .language .Document ;
27+ import graphql .normalized .nf .provider .NoOpNormalizedDocumentProvider ;
28+ import graphql .normalized .nf .provider .NormalizedDocumentProvider ;
2829import graphql .schema .GraphQLSchema ;
2930import graphql .validation .ValidationError ;
3031
@@ -158,6 +159,7 @@ public static GraphQLUnusualConfiguration.GraphQLContextConfiguration unusualCon
158159 private final ExecutionIdProvider idProvider ;
159160 private final Instrumentation instrumentation ;
160161 private final PreparsedDocumentProvider preparsedDocumentProvider ;
162+ private final NormalizedDocumentProvider normalizedDocumentProvider ;
161163 private final ValueUnboxer valueUnboxer ;
162164 private final boolean doNotAutomaticallyDispatchDataLoader ;
163165
@@ -170,6 +172,7 @@ private GraphQL(Builder builder) {
170172 this .idProvider = assertNotNull (builder .idProvider , () -> "idProvider must be non null" );
171173 this .instrumentation = assertNotNull (builder .instrumentation , () -> "instrumentation must not be null" );
172174 this .preparsedDocumentProvider = assertNotNull (builder .preparsedDocumentProvider , () -> "preparsedDocumentProvider must be non null" );
175+ this .normalizedDocumentProvider = assertNotNull (builder .normalizedDocumentProvider , () -> "normalizedDocumentProvider must be non null" );
173176 this .valueUnboxer = assertNotNull (builder .valueUnboxer , () -> "valueUnboxer must not be null" );
174177 this .doNotAutomaticallyDispatchDataLoader = builder .doNotAutomaticallyDispatchDataLoader ;
175178 }
@@ -227,6 +230,13 @@ public PreparsedDocumentProvider getPreparsedDocumentProvider() {
227230 return preparsedDocumentProvider ;
228231 }
229232
233+ /**
234+ * @return the NormalizedDocumentProvider for this {@link GraphQL} instance
235+ */
236+ public NormalizedDocumentProvider getNormalizedDocumentProvider () {
237+ return normalizedDocumentProvider ;
238+ }
239+
230240 /**
231241 * @return the ValueUnboxer for this {@link GraphQL} instance
232242 */
@@ -261,7 +271,8 @@ public GraphQL transform(Consumer<GraphQL.Builder> builderConsumer) {
261271 .subscriptionExecutionStrategy (this .subscriptionStrategy )
262272 .executionIdProvider (Optional .ofNullable (this .idProvider ).orElse (builder .idProvider ))
263273 .instrumentation (Optional .ofNullable (this .instrumentation ).orElse (builder .instrumentation ))
264- .preparsedDocumentProvider (Optional .ofNullable (this .preparsedDocumentProvider ).orElse (builder .preparsedDocumentProvider ));
274+ .preparsedDocumentProvider (Optional .ofNullable (this .preparsedDocumentProvider ).orElse (builder .preparsedDocumentProvider ))
275+ .normalizedDocumentProvider (Optional .ofNullable (this .normalizedDocumentProvider ).orElse (builder .normalizedDocumentProvider ));
265276
266277 builderConsumer .accept (builder );
267278
@@ -278,6 +289,7 @@ public static class Builder {
278289 private ExecutionIdProvider idProvider = DEFAULT_EXECUTION_ID_PROVIDER ;
279290 private Instrumentation instrumentation = null ; // deliberate default here
280291 private PreparsedDocumentProvider preparsedDocumentProvider = NoOpPreparsedDocumentProvider .INSTANCE ;
292+ private NormalizedDocumentProvider normalizedDocumentProvider = NoOpNormalizedDocumentProvider .INSTANCE ;
281293 private boolean doNotAutomaticallyDispatchDataLoader = false ;
282294 private ValueUnboxer valueUnboxer = ValueUnboxer .DEFAULT ;
283295
@@ -328,6 +340,18 @@ public Builder preparsedDocumentProvider(PreparsedDocumentProvider preparsedDocu
328340 return this ;
329341 }
330342
343+ /**
344+ * This allows you to set a {@link NormalizedDocumentProvider} that will be used to provide normalized documents
345+ *
346+ * @param normalizedDocumentProvider the provider of normalized documents
347+ *
348+ * @return this builder
349+ */
350+ public Builder normalizedDocumentProvider (NormalizedDocumentProvider normalizedDocumentProvider ) {
351+ this .normalizedDocumentProvider = normalizedDocumentProvider ;
352+ return this ;
353+ }
354+
331355 public Builder executionIdProvider (ExecutionIdProvider executionIdProvider ) {
332356 this .idProvider = assertNotNull (executionIdProvider , () -> "ExecutionIdProvider must be non null" );
333357 return this ;
@@ -497,7 +521,7 @@ public CompletableFuture<ExecutionResult> executeAsync(ExecutionInput executionI
497521
498522 GraphQLSchema graphQLSchema = instrumentation .instrumentSchema (this .graphQLSchema , instrumentationParameters , instrumentationState );
499523
500- CompletableFuture <ExecutionResult > executionResult = parseValidateAndExecute (instrumentedExecutionInput , graphQLSchema , instrumentationState , engineRunningState );
524+ CompletableFuture <ExecutionResult > executionResult = parseValidateAndExecute (instrumentedExecutionInput , graphQLSchema , instrumentationState , engineRunningState , normalizedDocumentProvider );
501525 //
502526 // finish up instrumentation
503527 executionResult = executionResult .whenComplete (completeInstrumentationCtxCF (executionInstrumentation ));
@@ -529,7 +553,7 @@ private ExecutionInput ensureInputHasId(ExecutionInput executionInput) {
529553 }
530554
531555
532- private CompletableFuture <ExecutionResult > parseValidateAndExecute (ExecutionInput executionInput , GraphQLSchema graphQLSchema , InstrumentationState instrumentationState , EngineRunningState engineRunningState ) {
556+ private CompletableFuture <ExecutionResult > parseValidateAndExecute (ExecutionInput executionInput , GraphQLSchema graphQLSchema , InstrumentationState instrumentationState , EngineRunningState engineRunningState , NormalizedDocumentProvider normalizedDocumentProvider ) {
533557 AtomicReference <ExecutionInput > executionInputRef = new AtomicReference <>(executionInput );
534558 Function <ExecutionInput , PreparsedDocumentEntry > computeFunction = transformedInput -> {
535559 // if they change the original query in the pre-parser, then we want to see it downstream from then on
@@ -542,7 +566,7 @@ private CompletableFuture<ExecutionResult> parseValidateAndExecute(ExecutionInpu
542566 return CompletableFuture .completedFuture (new ExecutionResultImpl (preparsedDocumentEntry .getErrors ()));
543567 }
544568 try {
545- return execute (executionInputRef .get (), preparsedDocumentEntry .getDocument (), graphQLSchema , instrumentationState , engineRunningState );
569+ return execute (executionInputRef .get (), preparsedDocumentEntry .getDocument (), graphQLSchema , instrumentationState , engineRunningState , normalizedDocumentProvider );
546570 } catch (AbortExecutionException e ) {
547571 return CompletableFuture .completedFuture (e .toExecutionResult ());
548572 }
@@ -606,10 +630,11 @@ private CompletableFuture<ExecutionResult> execute(ExecutionInput executionInput
606630 Document document ,
607631 GraphQLSchema graphQLSchema ,
608632 InstrumentationState instrumentationState ,
609- EngineRunningState engineRunningState
633+ EngineRunningState engineRunningState ,
634+ NormalizedDocumentProvider normalizedDocumentProvider
610635 ) {
611636
612- Execution execution = new Execution (queryStrategy , mutationStrategy , subscriptionStrategy , instrumentation , valueUnboxer , doNotAutomaticallyDispatchDataLoader );
637+ Execution execution = new Execution (queryStrategy , mutationStrategy , subscriptionStrategy , instrumentation , valueUnboxer , doNotAutomaticallyDispatchDataLoader , normalizedDocumentProvider );
613638 ExecutionId executionId = executionInput .getExecutionId ();
614639
615640 return execution .execute (document , graphQLSchema , executionId , executionInput , instrumentationState , engineRunningState );
0 commit comments