Package graphql.analysis
Class MaxQueryComplexityInstrumentation
java.lang.Object
graphql.execution.instrumentation.SimplePerformantInstrumentation
graphql.analysis.MaxQueryComplexityInstrumentation
- All Implemented Interfaces:
Instrumentation
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 returns true
a AbortExecutionException
is thrown.
-
Field Summary
Fields inherited from class graphql.execution.instrumentation.SimplePerformantInstrumentation
INSTANCE
-
Constructor Summary
ConstructorsConstructorDescriptionMaxQueryComplexityInstrumentation
(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, Function<QueryComplexityInfo, Boolean> maxQueryComplexityExceededFunction) new Instrumentation with custom complexity calculatorMaxQueryComplexityInstrumentation
(int maxComplexity, Function<QueryComplexityInfo, Boolean> maxQueryComplexityExceededFunction) new Instrumentation with default complexity calculator which is `1 + childComplexity` -
Method Summary
Modifier and TypeMethodDescription@Nullable InstrumentationContext
<ExecutionResult> beginExecuteOperation
(InstrumentationExecuteOperationParameters instrumentationExecuteOperationParameters, InstrumentationState rawState) This is called just before the execution of the query operation is started.@Nullable InstrumentationContext
<List<ValidationError>> beginValidation
(InstrumentationValidationParameters parameters, InstrumentationState rawState) This is called just before the parsed query document is validated.@Nullable 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 classMethods 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, beginFieldFetching
-
Constructor Details
-
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, Function<QueryComplexityInfo, 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, Function<QueryComplexityInfo, 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 Details
-
createStateAsync
public @Nullable 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
public @Nullable InstrumentationContext<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
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
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
-