Package graphql.analysis
Class MaxQueryDepthInstrumentation
java.lang.Object
graphql.execution.instrumentation.SimplePerformantInstrumentation
graphql.analysis.MaxQueryDepthInstrumentation
- All Implemented Interfaces:
Instrumentation
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 returns true a AbortExecutionException is thrown.
-
Field Summary
Fields inherited from class graphql.execution.instrumentation.SimplePerformantInstrumentation
INSTANCE -
Constructor Summary
ConstructorsConstructorDescriptionMaxQueryDepthInstrumentation(int maxDepth) Creates a new instrumentation that tracks the query depth.MaxQueryDepthInstrumentation(int maxDepth, Function<QueryDepthInfo, Boolean> maxQueryDepthExceededFunction) Creates a new instrumentation that tracks the query depth. -
Method Summary
Modifier and TypeMethodDescription@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 classMethods inherited from class graphql.execution.instrumentation.SimplePerformantInstrumentation
beginExecuteObject, beginExecution, beginExecutionStrategy, beginFieldCompletion, beginFieldExecution, beginFieldFetch, beginFieldListCompletion, beginParse, beginSubscribedFieldEvent, beginValidation, createState, createStateAsync, instrumentDataFetcher, instrumentDocumentAndVariables, instrumentExecutionContext, instrumentExecutionInput, instrumentExecutionResult, instrumentSchemaMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface graphql.execution.instrumentation.Instrumentation
beginDeferredField, beginFieldFetching, beginReactiveResults
-
Constructor Details
-
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, Function<QueryDepthInfo, 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 Details
-
beginExecuteOperation
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
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
-