Skip to content

Commit 8f049fe

Browse files
committed
This adds support for QueryAppliedDirective on operations and documents - used field to make it cheaper
1 parent 2e7c4fc commit 8f049fe

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/main/java/graphql/execution/Execution.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ public CompletableFuture<ExecutionResult> execute(Document document, GraphQLSche
111111
ResponseMapFactory responseMapFactory = GraphQL.unusualConfiguration(graphQLContext)
112112
.responseMapFactory().getOr(ResponseMapFactory.DEFAULT);
113113

114-
Map<OperationDefinition, ImmutableList<QueryAppliedDirective>> opDirectivesMap = operationDirectivesResolver.resolveDirectives(document, graphQLSchema, coercedVariables, graphQLContext, locale);
114+
Map<OperationDefinition, ImmutableList<QueryAppliedDirective>> operationDirectives = operationDirectivesResolver
115+
.resolveDirectives(document, graphQLSchema, coercedVariables, graphQLContext, locale);
115116

116117
ExecutionContext executionContext = newExecutionContextBuilder()
117118
.instrumentation(instrumentation)
@@ -130,7 +131,7 @@ public CompletableFuture<ExecutionResult> execute(Document document, GraphQLSche
130131
.normalizedVariableValues(normalizedVariableValues)
131132
.document(document)
132133
.operationDefinition(getOperationResult.operationDefinition)
133-
.operationDirectives(opDirectivesMap)
134+
.operationDirectives(operationDirectives)
134135
.dataLoaderRegistry(executionInput.getDataLoaderRegistry())
135136
.locale(locale)
136137
.valueUnboxer(valueUnboxer)

src/main/java/graphql/execution/ExecutionContext.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ public class ExecutionContext {
7575
private final ResultNodesInfo resultNodesInfo = new ResultNodesInfo();
7676
private final EngineRunningState engineRunningState;
7777

78-
private final Map<OperationDefinition, ImmutableList<QueryAppliedDirective>> opDirectivesMap;
78+
private final Map<OperationDefinition, ImmutableList<QueryAppliedDirective>> allOperationsDirectives;
79+
private final Map<String, ImmutableList<QueryAppliedDirective>> operationDirectives;
7980
private final Profiler profiler;
8081

8182
ExecutionContext(ExecutionContextBuilder builder) {
@@ -105,8 +106,10 @@ public class ExecutionContext {
105106
this.queryTree = FpKit.interThreadMemoize(() -> ExecutableNormalizedOperationFactory.createExecutableNormalizedOperation(graphQLSchema, operationDefinition, fragmentsByName, coercedVariables));
106107
this.propagateErrorsOnNonNullContractFailure = builder.propagateErrorsOnNonNullContractFailure;
107108
this.engineRunningState = builder.engineRunningState;
108-
this.opDirectivesMap = builder.opDirectivesMap;
109109
this.profiler = builder.profiler;
110+
this.allOperationsDirectives = builder.opDirectivesMap;
111+
List<QueryAppliedDirective> list = allOperationsDirectives.get(getOperationDefinition());
112+
this.operationDirectives = OperationDirectivesResolver.toAppliedDirectivesByName(list);
110113
}
111114

112115
public ExecutionId getExecutionId() {
@@ -145,16 +148,15 @@ public OperationDefinition getOperationDefinition() {
145148
* @return the map of {@link QueryAppliedDirective}s by name that were on this executing operation
146149
*/
147150
public Map<String, ImmutableList<QueryAppliedDirective>> getOperationDirectives() {
148-
List<QueryAppliedDirective> list = opDirectivesMap.get(getOperationDefinition());
149-
return OperationDirectivesResolver.toAppliedDirectivesByName(list);
151+
return operationDirectives;
150152
}
151153

152154
/**
153155
* @return the map of all the {@link QueryAppliedDirective}s that were on the {@link Document} including
154156
* {@link OperationDefinition}s that are not currently executing.
155157
*/
156158
public Map<OperationDefinition, ImmutableList<QueryAppliedDirective>> getAllOperationDirectives() {
157-
return opDirectivesMap;
159+
return allOperationsDirectives;
158160
}
159161

160162
public CoercedVariables getCoercedVariables() {

0 commit comments

Comments
 (0)