3636import java .util .function .Consumer ;
3737import java .util .function .Supplier ;
3838
39+ import static graphql .normalized .ExecutableNormalizedOperationFactory .*;
40+
3941@ SuppressWarnings ("TypeParameterUnusedInFormals" )
4042@ PublicApi
4143public class ExecutionContext {
@@ -75,8 +77,8 @@ public class ExecutionContext {
7577 private final ResultNodesInfo resultNodesInfo = new ResultNodesInfo ();
7678 private final EngineRunningState engineRunningState ;
7779
78- private final Map <OperationDefinition , ImmutableList <QueryAppliedDirective >> allOperationsDirectives ;
79- private final Map <String , ImmutableList <QueryAppliedDirective >> operationDirectives ;
80+ private final Supplier < Map <OperationDefinition , ImmutableList <QueryAppliedDirective > >> allOperationsDirectives ;
81+ private final Supplier < Map <String , ImmutableList <QueryAppliedDirective > >> operationDirectives ;
8082 private final Profiler profiler ;
8183
8284 ExecutionContext (ExecutionContextBuilder builder ) {
@@ -103,13 +105,27 @@ public class ExecutionContext {
103105 this .localContext = builder .localContext ;
104106 this .executionInput = builder .executionInput ;
105107 this .dataLoaderDispatcherStrategy = builder .dataLoaderDispatcherStrategy ;
106- this .queryTree = FpKit .interThreadMemoize (() -> ExecutableNormalizedOperationFactory .createExecutableNormalizedOperation (graphQLSchema , operationDefinition , fragmentsByName , coercedVariables ));
107108 this .propagateErrorsOnNonNullContractFailure = builder .propagateErrorsOnNonNullContractFailure ;
108109 this .engineRunningState = builder .engineRunningState ;
109110 this .profiler = builder .profiler ;
110- this .allOperationsDirectives = builder .opDirectivesMap ;
111- List <QueryAppliedDirective > list = allOperationsDirectives .get (getOperationDefinition ());
112- this .operationDirectives = OperationDirectivesResolver .toAppliedDirectivesByName (list );
111+ // lazy loading for performance
112+ this .queryTree = mkExecutableNormalizedOperation ();
113+ this .allOperationsDirectives = builder .allOperationsDirectives ;
114+ this .operationDirectives = mkOpDirectives (builder .allOperationsDirectives );
115+ }
116+
117+ private Supplier <ExecutableNormalizedOperation > mkExecutableNormalizedOperation () {
118+ return FpKit .interThreadMemoize (() -> {
119+ Options options = Options .defaultOptions ().graphQLContext (graphQLContext ).locale (locale );
120+ return createExecutableNormalizedOperation (graphQLSchema , operationDefinition , fragmentsByName , coercedVariables , options );
121+ });
122+ }
123+
124+ private Supplier <Map <String , ImmutableList <QueryAppliedDirective >>> mkOpDirectives (Supplier <Map <OperationDefinition , ImmutableList <QueryAppliedDirective >>> allOperationsDirectives ) {
125+ return FpKit .interThreadMemoize (() -> {
126+ List <QueryAppliedDirective > list = allOperationsDirectives .get ().get (operationDefinition );
127+ return OperationDirectivesResolver .toAppliedDirectivesByName (list );
128+ });
113129 }
114130
115131 public ExecutionId getExecutionId () {
@@ -148,15 +164,15 @@ public OperationDefinition getOperationDefinition() {
148164 * @return the map of {@link QueryAppliedDirective}s by name that were on this executing operation
149165 */
150166 public Map <String , ImmutableList <QueryAppliedDirective >> getOperationDirectives () {
151- return operationDirectives ;
167+ return operationDirectives . get () ;
152168 }
153169
154170 /**
155171 * @return the map of all the {@link QueryAppliedDirective}s that were on the {@link Document} including
156172 * {@link OperationDefinition}s that are not currently executing.
157173 */
158174 public Map <OperationDefinition , ImmutableList <QueryAppliedDirective >> getAllOperationDirectives () {
159- return allOperationsDirectives ;
175+ return allOperationsDirectives . get () ;
160176 }
161177
162178 public CoercedVariables getCoercedVariables () {
0 commit comments