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
FieldsModifier and TypeFieldDescriptionprivate static final org.slf4j.Loggerprivate final intprivate final Function<QueryDepthInfo, Boolean> Fields inherited from class 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.private intprotected AbortExecutionExceptionmkAbortException(int depth, int maxDepth) Called to generate your own error message or custom exception class(package private) QueryTraversernewQueryTraverser(ExecutionContext executionContext) Methods inherited from class SimplePerformantInstrumentation
beginExecuteOperation, beginExecution, beginExecution, beginExecutionStrategy, beginExecutionStrategy, beginField, beginField, beginFieldComplete, beginFieldComplete, beginFieldFetch, beginFieldFetch, beginFieldListComplete, beginFieldListComplete, beginParse, beginParse, beginSubscribedFieldEvent, beginSubscribedFieldEvent, beginValidation, beginValidation, createState, createState, createStateAsync, instrumentDataFetcher, instrumentDataFetcher, instrumentDocumentAndVariables, instrumentDocumentAndVariables, instrumentExecutionContext, instrumentExecutionContext, instrumentExecutionInput, instrumentExecutionInput, instrumentExecutionResult, instrumentExecutionResult, instrumentSchema, instrumentSchema
-
Field Details
-
log
private static final org.slf4j.Logger log -
maxDepth
private final int maxDepth -
maxQueryDepthExceededFunction
-
-
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
@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.createState(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
-
newQueryTraverser
-
getPathLength
-