Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import graphql.execution.instrumentation.parameters.InstrumentationValidationParameters;
import graphql.validation.ValidationError;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

import java.util.List;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -85,15 +86,15 @@ public CompletableFuture<InstrumentationState> createStateAsync(InstrumentationC
}

@Override
public InstrumentationContext<List<ValidationError>> beginValidation(InstrumentationValidationParameters parameters, InstrumentationState rawState) {
public InstrumentationContext<List<ValidationError>> beginValidation(InstrumentationValidationParameters parameters, @Nullable InstrumentationState rawState) {
State state = ofState(rawState);
// for API backwards compatibility reasons we capture the validation parameters, so we can put them into QueryComplexityInfo
state.instrumentationValidationParameters.set(parameters);
return noOp();
}

@Override
public InstrumentationContext<ExecutionResult> beginExecuteOperation(InstrumentationExecuteOperationParameters instrumentationExecuteOperationParameters, InstrumentationState rawState) {
public InstrumentationContext<ExecutionResult> beginExecuteOperation(InstrumentationExecuteOperationParameters instrumentationExecuteOperationParameters, @Nullable InstrumentationState rawState) {
State state = ofState(rawState);
QueryComplexityCalculator queryComplexityCalculator = newQueryComplexityCalculator(instrumentationExecuteOperationParameters.getExecutionContext());
int totalComplexity = queryComplexityCalculator.calculate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public MaxQueryDepthInstrumentation(int maxDepth, Function<QueryDepthInfo, Boole
}

@Override
public InstrumentationContext<ExecutionResult> beginExecuteOperation(InstrumentationExecuteOperationParameters parameters, InstrumentationState state) {
public InstrumentationContext<ExecutionResult> beginExecuteOperation(InstrumentationExecuteOperationParameters parameters, @Nullable InstrumentationState state) {
QueryTraverser queryTraverser = newQueryTraverser(parameters.getExecutionContext());
int depth = queryTraverser.reducePreOrder((env, acc) -> Math.max(getPathLength(env.getParentEnvironment()), acc), 0);
if (depth > maxDepth) {
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,13 @@ default InstrumentationState createState(InstrumentationCreateStateParameters pa
* This is called right at the start of query execution, and it's the first step in the instrumentation chain.
*
* @param parameters the parameters to this step
* @param state the state created during the call to {@link #createStateAsync(InstrumentationCreateStateParameters)}
* @param state the state created during the call to {@link #createStateAsync(InstrumentationCreateStateParameters)},
* or {@code null} when createState/createStateAsync returns null
*
* @return a nullable {@link InstrumentationContext} object that will be called back when the step ends (assuming it's not null)
*/
@Nullable
default InstrumentationContext<ExecutionResult> beginExecution(InstrumentationExecutionParameters parameters, InstrumentationState state) {
default InstrumentationContext<ExecutionResult> beginExecution(InstrumentationExecutionParameters parameters, @Nullable InstrumentationState state) {
return noOp();
}

Expand All @@ -91,7 +92,7 @@ default InstrumentationContext<ExecutionResult> beginExecution(InstrumentationEx
* @return a nullable {@link InstrumentationContext} object that will be called back when the step ends (assuming it's not null)
*/
@Nullable
default InstrumentationContext<Document> beginParse(InstrumentationExecutionParameters parameters, InstrumentationState state) {
default InstrumentationContext<Document> beginParse(InstrumentationExecutionParameters parameters, @Nullable InstrumentationState state) {
return noOp();
}

Expand All @@ -104,7 +105,7 @@ default InstrumentationContext<Document> beginParse(InstrumentationExecutionPara
* @return a nullable {@link InstrumentationContext} object that will be called back when the step ends (assuming it's not null)
*/
@Nullable
default InstrumentationContext<List<ValidationError>> beginValidation(InstrumentationValidationParameters parameters, InstrumentationState state) {
default InstrumentationContext<List<ValidationError>> beginValidation(InstrumentationValidationParameters parameters, @Nullable InstrumentationState state) {
return noOp();
}

Expand All @@ -117,7 +118,7 @@ default InstrumentationContext<List<ValidationError>> beginValidation(Instrument
* @return a nullable {@link InstrumentationContext} object that will be called back when the step ends (assuming it's not null)
*/
@Nullable
default InstrumentationContext<ExecutionResult> beginExecuteOperation(InstrumentationExecuteOperationParameters parameters, InstrumentationState state) {
default InstrumentationContext<ExecutionResult> beginExecuteOperation(InstrumentationExecuteOperationParameters parameters, @Nullable InstrumentationState state) {
return noOp();
}

Expand All @@ -132,7 +133,7 @@ default InstrumentationContext<ExecutionResult> beginExecuteOperation(Instrument
* @return a nullable {@link InstrumentationContext} object that will be called back when the step ends (assuming it's not null)
*/
@Nullable
default InstrumentationContext<Void> beginReactiveResults(InstrumentationReactiveResultsParameters parameters, InstrumentationState state) {
default InstrumentationContext<Void> beginReactiveResults(InstrumentationReactiveResultsParameters parameters, @Nullable InstrumentationState state) {
return noOp();
}

Expand All @@ -146,7 +147,7 @@ default InstrumentationContext<Void> beginReactiveResults(InstrumentationReactiv
* @return a nullable {@link ExecutionStrategyInstrumentationContext} object that will be called back when the step ends (assuming it's not null)
*/
@Nullable
default ExecutionStrategyInstrumentationContext beginExecutionStrategy(InstrumentationExecutionStrategyParameters parameters, InstrumentationState state) {
default ExecutionStrategyInstrumentationContext beginExecutionStrategy(InstrumentationExecutionStrategyParameters parameters, @Nullable InstrumentationState state) {
return ExecutionStrategyInstrumentationContext.NOOP;
}

Expand All @@ -160,7 +161,7 @@ default ExecutionStrategyInstrumentationContext beginExecutionStrategy(Instrumen
* @return a nullable {@link ExecutionStrategyInstrumentationContext} object that will be called back when the step ends (assuming it's not null)
*/
@Nullable
default ExecuteObjectInstrumentationContext beginExecuteObject(InstrumentationExecutionStrategyParameters parameters, InstrumentationState state) {
default ExecuteObjectInstrumentationContext beginExecuteObject(InstrumentationExecutionStrategyParameters parameters, @Nullable InstrumentationState state) {
return ExecuteObjectInstrumentationContext.NOOP;
}

Expand All @@ -176,7 +177,7 @@ default ExecuteObjectInstrumentationContext beginExecuteObject(InstrumentationEx
*/
@ExperimentalApi
@Nullable
default InstrumentationContext<Object> beginDeferredField(InstrumentationFieldParameters parameters, InstrumentationState state) {
default InstrumentationContext<Object> beginDeferredField(InstrumentationFieldParameters parameters, @Nullable InstrumentationState state) {
return noOp();
}

Expand All @@ -189,7 +190,7 @@ default InstrumentationContext<Object> beginDeferredField(InstrumentationFieldPa
* @return a nullable {@link InstrumentationContext} object that will be called back when the step ends (assuming it's not null)
*/
@Nullable
default InstrumentationContext<ExecutionResult> beginSubscribedFieldEvent(InstrumentationFieldParameters parameters, InstrumentationState state) {
default InstrumentationContext<ExecutionResult> beginSubscribedFieldEvent(InstrumentationFieldParameters parameters, @Nullable InstrumentationState state) {
return noOp();
}

Expand All @@ -202,7 +203,7 @@ default InstrumentationContext<ExecutionResult> beginSubscribedFieldEvent(Instru
* @return a nullable {@link InstrumentationContext} object that will be called back when the step ends (assuming it's not null)
*/
@Nullable
default InstrumentationContext<Object> beginFieldExecution(InstrumentationFieldParameters parameters, InstrumentationState state) {
default InstrumentationContext<Object> beginFieldExecution(InstrumentationFieldParameters parameters, @Nullable InstrumentationState state) {
return noOp();
}

Expand All @@ -219,7 +220,7 @@ default InstrumentationContext<Object> beginFieldExecution(InstrumentationFieldP
*/
@Deprecated(since = "2024-04-18")
@Nullable
default InstrumentationContext<Object> beginFieldFetch(InstrumentationFieldFetchParameters parameters, InstrumentationState state) {
default InstrumentationContext<Object> beginFieldFetch(InstrumentationFieldFetchParameters parameters, @Nullable InstrumentationState state) {
return noOp();
}

Expand All @@ -239,7 +240,7 @@ default InstrumentationContext<Object> beginFieldFetch(InstrumentationFieldFetch
* @return a nullable {@link InstrumentationContext} object that will be called back when the step ends (assuming it's not null)
*/
@Nullable
default FieldFetchingInstrumentationContext beginFieldFetching(InstrumentationFieldFetchParameters parameters, InstrumentationState state) {
default FieldFetchingInstrumentationContext beginFieldFetching(InstrumentationFieldFetchParameters parameters, @Nullable InstrumentationState state) {
InstrumentationContext<Object> ctx = beginFieldFetch(parameters, state);
if (ctx == noOp()) {
return FieldFetchingInstrumentationContext.NOOP;
Expand All @@ -256,7 +257,7 @@ default FieldFetchingInstrumentationContext beginFieldFetching(InstrumentationFi
* @return a nullable {@link InstrumentationContext} object that will be called back when the step ends (assuming it's not null)
*/
@Nullable
default InstrumentationContext<Object> beginFieldCompletion(InstrumentationFieldCompleteParameters parameters, InstrumentationState state) {
default InstrumentationContext<Object> beginFieldCompletion(InstrumentationFieldCompleteParameters parameters, @Nullable InstrumentationState state) {
return noOp();
}

Expand All @@ -269,7 +270,7 @@ default InstrumentationContext<Object> beginFieldCompletion(InstrumentationField
* @return a nullable {@link InstrumentationContext} object that will be called back when the step ends (assuming it's not null)
*/
@Nullable
default InstrumentationContext<Object> beginFieldListCompletion(InstrumentationFieldCompleteParameters parameters, InstrumentationState state) {
default InstrumentationContext<Object> beginFieldListCompletion(InstrumentationFieldCompleteParameters parameters, @Nullable InstrumentationState state) {
return noOp();
}

Expand All @@ -284,7 +285,7 @@ default InstrumentationContext<Object> beginFieldListCompletion(InstrumentationF
* @return a non-null instrumented ExecutionInput, the default is to return to the same object
*/
@NonNull
default ExecutionInput instrumentExecutionInput(ExecutionInput executionInput, InstrumentationExecutionParameters parameters, InstrumentationState state) {
default ExecutionInput instrumentExecutionInput(ExecutionInput executionInput, InstrumentationExecutionParameters parameters, @Nullable InstrumentationState state) {
return executionInput;
}

Expand All @@ -298,7 +299,7 @@ default ExecutionInput instrumentExecutionInput(ExecutionInput executionInput, I
* @return a non-null instrumented DocumentAndVariables, the default is to return to the same objects
*/
@NonNull
default DocumentAndVariables instrumentDocumentAndVariables(DocumentAndVariables documentAndVariables, InstrumentationExecutionParameters parameters, InstrumentationState state) {
default DocumentAndVariables instrumentDocumentAndVariables(DocumentAndVariables documentAndVariables, InstrumentationExecutionParameters parameters, @Nullable InstrumentationState state) {
return documentAndVariables;
}

Expand All @@ -313,7 +314,7 @@ default DocumentAndVariables instrumentDocumentAndVariables(DocumentAndVariables
* @return a non-null instrumented GraphQLSchema, the default is to return to the same object
*/
@NonNull
default GraphQLSchema instrumentSchema(GraphQLSchema schema, InstrumentationExecutionParameters parameters, InstrumentationState state) {
default GraphQLSchema instrumentSchema(GraphQLSchema schema, InstrumentationExecutionParameters parameters, @Nullable InstrumentationState state) {
return schema;
}

Expand All @@ -328,7 +329,7 @@ default GraphQLSchema instrumentSchema(GraphQLSchema schema, InstrumentationExec
* @return a non-null instrumented ExecutionContext, the default is to return to the same object
*/
@NonNull
default ExecutionContext instrumentExecutionContext(ExecutionContext executionContext, InstrumentationExecutionParameters parameters, InstrumentationState state) {
default ExecutionContext instrumentExecutionContext(ExecutionContext executionContext, InstrumentationExecutionParameters parameters, @Nullable InstrumentationState state) {
return executionContext;
}

Expand All @@ -345,7 +346,7 @@ default ExecutionContext instrumentExecutionContext(ExecutionContext executionCo
* @return a non-null instrumented DataFetcher, the default is to return to the same object
*/
@NonNull
default DataFetcher<?> instrumentDataFetcher(DataFetcher<?> dataFetcher, InstrumentationFieldFetchParameters parameters, InstrumentationState state) {
default DataFetcher<?> instrumentDataFetcher(DataFetcher<?> dataFetcher, InstrumentationFieldFetchParameters parameters, @Nullable InstrumentationState state) {
return dataFetcher;
}

Expand All @@ -359,7 +360,7 @@ default DataFetcher<?> instrumentDataFetcher(DataFetcher<?> dataFetcher, Instrum
* @return a new execution result completable future
*/
@NonNull
default CompletableFuture<ExecutionResult> instrumentExecutionResult(ExecutionResult executionResult, InstrumentationExecutionParameters parameters, InstrumentationState state) {
default CompletableFuture<ExecutionResult> instrumentExecutionResult(ExecutionResult executionResult, InstrumentationExecutionParameters parameters, @Nullable InstrumentationState state) {
return CompletableFuture.completedFuture(executionResult);
}
}
Loading