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 Modifier and Type Field Description private static org.slf4j.Loggerlogprivate intmaxDepthprivate java.util.function.Function<QueryDepthInfo,java.lang.Boolean>maxQueryDepthExceededFunction-
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.private intgetPathLength(QueryVisitorFieldEnvironment path)protected 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 graphql.execution.instrumentation.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 Detail
-
log
private static final org.slf4j.Logger log
-
maxDepth
private final int maxDepth
-
maxQueryDepthExceededFunction
private final java.util.function.Function<QueryDepthInfo,java.lang.Boolean> maxQueryDepthExceededFunction
-
-
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.createState(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
-
newQueryTraverser
QueryTraverser newQueryTraverser(ExecutionContext executionContext)
-
getPathLength
private int getPathLength(QueryVisitorFieldEnvironment path)
-
-