Repository navigation
Conversation
…eters InstrumentationFieldFetchParameters.getField() previously went through the ExecutionStepInfo supplier, which is backed by the lazily built DataFetchingEnvironment. Any instrumentation that only wanted the field definition in beginFieldFetching therefore paid for a DataFetchingEnvironmentImpl plus ExecutionStepInfo on every fetch, even for trivial PropertyDataFetcher fetches that never build the environment themselves. ExecutionStrategy.fetchField already resolves the GraphQLFieldDefinition eagerly, so pass it into the parameters and have getField() return it directly without touching the supplier. The existing public constructors are kept and delegate with a null field definition, which falls back to the supplier path. Motivated by apollographql/federation-jvm#469. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…docs The override in InstrumentationFieldFetchParameters only delegated to super and existed to carry Javadoc, so its guidance now lives on getEnvironment(). Also rename the misnamed getExecutionContext constructor parameter, keep the base class Javadoc to what it knows about (the ExecutionStepInfo supplier), and import ExecutionStepInfo in the test instead of using the fully-qualified name. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The engine-level test now checks that beginFieldExecution and beginFieldFetching both receive the field definition eagerly, so it fails if ExecutionStrategy stops passing fieldDef. Previously it only checked getField() results, which were correct either way. Reword the getField() Javadoc to say the fallback reads the ExecutionStepInfo supplier, which is what the code has always done. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… into cheap-field-definition-accessor
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
InstrumentationFieldFetchParameters.getField()(inherited fromInstrumentationFieldParameters) goes through theExecutionStepInfosupplier, which is() -> environment.get().getExecutionStepInfo(). So asking for the field definition inbeginFieldFetchingmaterialises the full lazily builtDataFetchingEnvironmentImplplus itsExecutionStepInfoon every fetch. For trivialPropertyDataFetcherfetches (aLightDataFetcherthat never builds the environment itself) the instrumentation becomes the only reason the environment is built at all.ExecutionStrategy.fetchFieldalready has theGraphQLFieldDefinitionresolved eagerly before the environment supplier is created, so this cost is avoidable.Motivating case: apollographql/federation-jvm#469 (see the "Possible follow-up in graphql-java" discussion) and apollographql/federation-jvm#470, whose
isLeafField()check has to callparameters.getEnvironment().getFieldType()and notes this cost as unavoidable today.Change
InstrumentationFieldParametersgains a@Nullable GraphQLFieldDefinitionand a new constructor(ExecutionContext, @Nullable GraphQLFieldDefinition, Supplier<ExecutionStepInfo>).getField()returns the definition directly when it was supplied and otherwise falls back to the existing supplier path. The existing public constructor is unchanged and delegates withnull.InstrumentationFieldFetchParametersgains the matching constructor(ExecutionContext, @Nullable GraphQLFieldDefinition, Supplier<DataFetchingEnvironment>, ExecutionStrategyParameters, boolean), and passes the definition tosuper.getField()is inherited and now returns the eager definition; thegetEnvironment()Javadoc points instrumentations that only need the field definition atgetField()since it does not build the environment. The existing public constructor is unchanged and delegates withnull.ExecutionStrategypasses the already resolvedfieldDefat both construction sites (beginFieldExecutionandbeginFieldFetching). These were the only two construction sites in main or test code.SubscriptionExecutionStrategyandDeferredExecutionSupportstill use the old constructor as they only hold a step info supplier there.getEnvironment()andgetExecutionStepInfo()are untouched: they return the same objects and materialise at the same time as before.TracingInstrumentationis not changed in this PR; a follow-up could usegetField()there.Before / after for
getField()inbeginFieldFetchingDataFetchingEnvironmentImpl,ExecutionStepInfo(viacreateExecutionStepInfo), argument/normalized field suppliers,DataFetchingFieldSelectionSetImpl,QueryDirectivesImplenvironment.get())executionStepInfo.get().getFieldDefinition()GraphQLFieldDefinitionfetchFieldalready hadSo an instrumentation can now do
GraphQLTypeUtil.isLeaf(parameters.getField().getType())on every fetch for free, and only pay for the environment when it actually callsgetEnvironment().Tests
New Spock spec
InstrumentationFieldFetchParametersTest:getField()with a throwing environmentSupplierreturns the supplied definition andGraphQLTypeUtil.isLeafworks on it, proving the supplier is never invoked.InstrumentationFieldParameterswith a throwingExecutionStepInfosupplier.SimplePerformantInstrumentationreadsparameters.getField()inbeginFieldFetchingagainst a real schema and sees the right leaf/non-leaf classification per field../gradlew test(JDK 25 toolchain):6076 tests, 7 skipped, 0 failures, 0 errors.
🤖 Generated with Claude Code