|
19 | 19 | import graphql.introspection.Introspection; |
20 | 20 | import graphql.language.Argument; |
21 | 21 | import graphql.language.Field; |
| 22 | +import graphql.normalized.NormalizedField; |
| 23 | +import graphql.normalized.NormalizedQueryTree; |
22 | 24 | import graphql.schema.CoercingSerializeException; |
23 | 25 | import graphql.schema.DataFetcher; |
24 | 26 | import graphql.schema.DataFetchingEnvironment; |
@@ -190,7 +192,7 @@ protected CompletableFuture<ExecutionResult> resolveField(ExecutionContext execu |
190 | 192 | */ |
191 | 193 | protected CompletableFuture<FieldValueInfo> resolveFieldWithInfo(ExecutionContext executionContext, ExecutionStrategyParameters parameters) { |
192 | 194 | GraphQLFieldDefinition fieldDef = getFieldDef(executionContext, parameters, parameters.getField().getSingleField()); |
193 | | - Supplier<ExecutionStepInfo> executionStepInfo = FpKit.memoize(() -> createExecutionStepInfo(executionContext, parameters, fieldDef, null)); |
| 195 | + Supplier<ExecutionStepInfo> executionStepInfo = FpKit.intraThreadMemoize(() -> createExecutionStepInfo(executionContext, parameters, fieldDef, null)); |
194 | 196 |
|
195 | 197 | Instrumentation instrumentation = executionContext.getInstrumentation(); |
196 | 198 | InstrumentationContext<ExecutionResult> fieldCtx = instrumentation.beginField( |
@@ -235,15 +237,17 @@ protected CompletableFuture<FetchedValue> fetchField(ExecutionContext executionC |
235 | 237 | GraphQLCodeRegistry codeRegistry = executionContext.getGraphQLSchema().getCodeRegistry(); |
236 | 238 | GraphQLOutputType fieldType = fieldDef.getType(); |
237 | 239 |
|
238 | | - // DataFetchingFieldSelectionSet and QueryDirectives is a supplier of sorts - eg a lazy pattern |
239 | | - DataFetchingFieldSelectionSet fieldCollector = DataFetchingFieldSelectionSetImpl.newCollector(executionContext, fieldType, parameters.getField()); |
240 | | - QueryDirectives queryDirectives = new QueryDirectivesImpl(field, executionContext.getGraphQLSchema(), executionContext.getVariables()); |
241 | | - |
242 | 240 | // if the DF (like PropertyDataFetcher) does not use the arguments of execution step info then dont build any |
243 | | - Supplier<ExecutionStepInfo> executionStepInfo = FpKit.memoize( |
| 241 | + Supplier<ExecutionStepInfo> executionStepInfo = FpKit.intraThreadMemoize( |
244 | 242 | () -> createExecutionStepInfo(executionContext, parameters, fieldDef, parentType)); |
245 | 243 | Supplier<Map<String, Object>> argumentValues = () -> executionStepInfo.get().getArguments(); |
246 | 244 |
|
| 245 | + Supplier<NormalizedField> normalizedFieldSupplier = getNormalizedField(executionContext, parameters, executionStepInfo); |
| 246 | + |
| 247 | + // DataFetchingFieldSelectionSet and QueryDirectives is a supplier of sorts - eg a lazy pattern |
| 248 | + DataFetchingFieldSelectionSet fieldCollector = DataFetchingFieldSelectionSetImpl.newCollector(fieldType, normalizedFieldSupplier); |
| 249 | + QueryDirectives queryDirectives = new QueryDirectivesImpl(field, executionContext.getGraphQLSchema(), executionContext.getVariables()); |
| 250 | + |
247 | 251 |
|
248 | 252 | DataFetchingEnvironment environment = newDataFetchingEnvironment(executionContext) |
249 | 253 | .source(parameters.getSource()) |
@@ -293,6 +297,11 @@ protected CompletableFuture<FetchedValue> fetchField(ExecutionContext executionC |
293 | 297 | .thenApply(result -> unboxPossibleDataFetcherResult(executionContext, parameters, result)); |
294 | 298 | } |
295 | 299 |
|
| 300 | + protected Supplier<NormalizedField> getNormalizedField(ExecutionContext executionContext, ExecutionStrategyParameters parameters, Supplier<ExecutionStepInfo> executionStepInfo) { |
| 301 | + Supplier<NormalizedQueryTree> normalizedQuery = executionContext.getNormalizedQueryTree(); |
| 302 | + return () -> normalizedQuery.get().getNormalizedField(parameters.getField(), executionStepInfo.get().getObjectType(), executionStepInfo.get().getPath()); |
| 303 | + } |
| 304 | + |
296 | 305 | protected FetchedValue unboxPossibleDataFetcherResult(ExecutionContext executionContext, |
297 | 306 | ExecutionStrategyParameters parameters, |
298 | 307 | Object result) { |
|
0 commit comments