Package graphql.analysis
Class MaxQueryDepthInstrumentation
- java.lang.Object
-
- graphql.execution.instrumentation.SimplePerformantInstrumentation
-
- graphql.analysis.MaxQueryDepthInstrumentation
-
- All Implemented Interfaces:
Instrumentation
@PublicApi public class MaxQueryDepthInstrumentation extends SimplePerformantInstrumentation
Prevents execution if the query depth is greater than the specified maxDepth.Use the
Function<QueryDepthInfo, Boolean>parameter to supply a function to perform a custom action when the max depth is exceeded. If the function returnstrueaAbortExecutionExceptionis thrown.
-
-
Field Summary
-
Fields inherited from class graphql.execution.instrumentation.SimplePerformantInstrumentation
INSTANCE
-
-
Constructor Summary
Constructors Constructor Description MaxQueryDepthInstrumentation(int maxDepth)Creates a new instrumentation that tracks the query depth.MaxQueryDepthInstrumentation(int maxDepth, java.util.function.Function<QueryDepthInfo,java.lang.Boolean> maxQueryDepthExceededFunction)Creates a new instrumentation that tracks the query depth.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description @Nullable InstrumentationContext<ExecutionResult>beginExecuteOperation(InstrumentationExecuteOperationParameters parameters, InstrumentationState state)This is called just before the execution of the query operation is started.protected AbortExecutionExceptionmkAbortException(int depth, int maxDepth)Called to generate your own error message or custom exception class-
Methods inherited from class graphql.execution.instrumentation.SimplePerformantInstrumentation
beginExecuteObject, beginExecution, beginExecutionStrategy, beginFieldCompletion, beginFieldExecution, beginFieldFetch, beginFieldListCompletion, beginParse, beginSubscribedFieldEvent, beginValidation, createState, createStateAsync, instrumentDataFetcher, instrumentDocumentAndVariables, instrumentExecutionContext, instrumentExecutionInput, instrumentExecutionResult, instrumentSchema
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface graphql.execution.instrumentation.Instrumentation
beginDeferredField, beginFieldFetching
-
-
-
-
Constructor Detail
-
MaxQueryDepthInstrumentation
public MaxQueryDepthInstrumentation(int maxDepth)
Creates a new instrumentation that tracks the query depth.- Parameters:
maxDepth- max allowed depth, otherwise execution will be aborted
-
MaxQueryDepthInstrumentation
public MaxQueryDepthInstrumentation(int maxDepth, java.util.function.Function<QueryDepthInfo,java.lang.Boolean> maxQueryDepthExceededFunction)Creates a new instrumentation that tracks the query depth.- Parameters:
maxDepth- max allowed depth, otherwise execution will be abortedmaxQueryDepthExceededFunction- the function to perform when the max depth is exceeded
-
-
Method Detail
-
beginExecuteOperation
@Nullable public @Nullable InstrumentationContext<ExecutionResult> beginExecuteOperation(InstrumentationExecuteOperationParameters parameters, InstrumentationState state)
Description copied from interface:InstrumentationThis is called just before the execution of the query operation is started.- Specified by:
beginExecuteOperationin interfaceInstrumentation- Overrides:
beginExecuteOperationin classSimplePerformantInstrumentation- Parameters:
parameters- the parameters to this stepstate- the state created during the call toInstrumentation.createStateAsync(InstrumentationCreateStateParameters)- Returns:
- a nullable
InstrumentationContextobject that will be called back when the step ends (assuming it's not null)
-
mkAbortException
protected AbortExecutionException mkAbortException(int depth, int maxDepth)
Called to generate your own error message or custom exception class- Parameters:
depth- the depth of the querymaxDepth- the maximum depth allowed- Returns:
- an instance of AbortExecutionException
-
-