Package graphql.analysis
Class MaxQueryComplexityInstrumentation
- java.lang.Object
-
- graphql.execution.instrumentation.SimplePerformantInstrumentation
-
- graphql.analysis.MaxQueryComplexityInstrumentation
-
- All Implemented Interfaces:
Instrumentation
@PublicApi public class MaxQueryComplexityInstrumentation extends SimplePerformantInstrumentation
Prevents execution if the query complexity is greater than the specified maxComplexity.Use the
Function<QueryComplexityInfo, Boolean>
parameter to supply a function to perform a custom action when the max complexity is exceeded. If the function returnstrue
aAbortExecutionException
is thrown.
-
-
Field Summary
-
Fields inherited from class graphql.execution.instrumentation.SimplePerformantInstrumentation
INSTANCE
-
-
Constructor Summary
Constructors Constructor Description MaxQueryComplexityInstrumentation(int maxComplexity)
new Instrumentation with default complexity calculator which is `1 + childComplexity`MaxQueryComplexityInstrumentation(int maxComplexity, FieldComplexityCalculator fieldComplexityCalculator)
new Instrumentation with custom complexity calculatorMaxQueryComplexityInstrumentation(int maxComplexity, FieldComplexityCalculator fieldComplexityCalculator, java.util.function.Function<QueryComplexityInfo,java.lang.Boolean> maxQueryComplexityExceededFunction)
new Instrumentation with custom complexity calculatorMaxQueryComplexityInstrumentation(int maxComplexity, java.util.function.Function<QueryComplexityInfo,java.lang.Boolean> maxQueryComplexityExceededFunction)
new Instrumentation with default complexity calculator which is `1 + childComplexity`
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description @Nullable InstrumentationContext<ExecutionResult>
beginExecuteOperation(InstrumentationExecuteOperationParameters instrumentationExecuteOperationParameters, InstrumentationState rawState)
This is called just before the execution of the query operation is started.@Nullable InstrumentationContext<java.util.List<ValidationError>>
beginValidation(InstrumentationValidationParameters parameters, InstrumentationState rawState)
This is called just before the parsed query document is validated.@Nullable java.util.concurrent.CompletableFuture<InstrumentationState>
createStateAsync(InstrumentationCreateStateParameters parameters)
This will be called just before execution to create an object, in an asynchronous manner, that is given back to all instrumentation methods to allow them to have per execution request stateprotected AbortExecutionException
mkAbortException(int totalComplexity, int maxComplexity)
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, createState, 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
-
-
-
-
Constructor Detail
-
MaxQueryComplexityInstrumentation
public MaxQueryComplexityInstrumentation(int maxComplexity)
new Instrumentation with default complexity calculator which is `1 + childComplexity`- Parameters:
maxComplexity
- max allowed complexity, otherwise execution will be aborted
-
MaxQueryComplexityInstrumentation
public MaxQueryComplexityInstrumentation(int maxComplexity, java.util.function.Function<QueryComplexityInfo,java.lang.Boolean> maxQueryComplexityExceededFunction)
new Instrumentation with default complexity calculator which is `1 + childComplexity`- Parameters:
maxComplexity
- max allowed complexity, otherwise execution will be abortedmaxQueryComplexityExceededFunction
- the function to perform when the max complexity is exceeded
-
MaxQueryComplexityInstrumentation
public MaxQueryComplexityInstrumentation(int maxComplexity, FieldComplexityCalculator fieldComplexityCalculator)
new Instrumentation with custom complexity calculator- Parameters:
maxComplexity
- max allowed complexity, otherwise execution will be abortedfieldComplexityCalculator
- custom complexity calculator
-
MaxQueryComplexityInstrumentation
public MaxQueryComplexityInstrumentation(int maxComplexity, FieldComplexityCalculator fieldComplexityCalculator, java.util.function.Function<QueryComplexityInfo,java.lang.Boolean> maxQueryComplexityExceededFunction)
new Instrumentation with custom complexity calculator- Parameters:
maxComplexity
- max allowed complexity, otherwise execution will be abortedfieldComplexityCalculator
- custom complexity calculatormaxQueryComplexityExceededFunction
- the function to perform when the max complexity is exceeded
-
-
Method Detail
-
createStateAsync
@Nullable public @Nullable java.util.concurrent.CompletableFuture<InstrumentationState> createStateAsync(InstrumentationCreateStateParameters parameters)
Description copied from interface:Instrumentation
This will be called just before execution to create an object, in an asynchronous manner, that is given back to all instrumentation methods to allow them to have per execution request state- Specified by:
createStateAsync
in interfaceInstrumentation
- Overrides:
createStateAsync
in classSimplePerformantInstrumentation
- Parameters:
parameters
- the parameters to this step- Returns:
- a state object that is passed to each method
-
beginValidation
@Nullable public @Nullable InstrumentationContext<java.util.List<ValidationError>> beginValidation(InstrumentationValidationParameters parameters, InstrumentationState rawState)
Description copied from interface:Instrumentation
This is called just before the parsed query document is validated.- Specified by:
beginValidation
in interfaceInstrumentation
- Overrides:
beginValidation
in classSimplePerformantInstrumentation
- Parameters:
parameters
- the parameters to this steprawState
- the state created during the call toInstrumentation.createStateAsync(InstrumentationCreateStateParameters)
- Returns:
- a nullable
InstrumentationContext
object that will be called back when the step ends (assuming it's not null)
-
beginExecuteOperation
@Nullable public @Nullable InstrumentationContext<ExecutionResult> beginExecuteOperation(InstrumentationExecuteOperationParameters instrumentationExecuteOperationParameters, InstrumentationState rawState)
Description copied from interface:Instrumentation
This is called just before the execution of the query operation is started.- Specified by:
beginExecuteOperation
in interfaceInstrumentation
- Overrides:
beginExecuteOperation
in classSimplePerformantInstrumentation
- Parameters:
instrumentationExecuteOperationParameters
- the parameters to this steprawState
- the state created during the call toInstrumentation.createStateAsync(InstrumentationCreateStateParameters)
- Returns:
- a nullable
InstrumentationContext
object that will be called back when the step ends (assuming it's not null)
-
mkAbortException
protected AbortExecutionException mkAbortException(int totalComplexity, int maxComplexity)
Called to generate your own error message or custom exception class- Parameters:
totalComplexity
- the complexity of the querymaxComplexity
- the maximum complexity allowed- Returns:
- an instance of AbortExecutionException
-
-