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.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final FieldComplexityCalculatorprivate static final org.slf4j.Loggerprivate final intprivate final Function<QueryComplexityInfo, Boolean> Fields inherited from class 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.createState(InstrumentationCreateStateParameters parameters) This will be called just before execution to create an object that is given back to all instrumentation methods to allow them to have per execution request stateprotected AbortExecutionExceptionmkAbortException(int totalComplexity, int maxComplexity) Called to generate your own error message or custom exception classprivate QueryComplexityCalculatornewQueryComplexityCalculator(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, createState, createStateAsync, instrumentDataFetcher, instrumentDataFetcher, instrumentDocumentAndVariables, instrumentDocumentAndVariables, instrumentExecutionContext, instrumentExecutionContext, instrumentExecutionInput, instrumentExecutionInput, instrumentExecutionResult, instrumentExecutionResult, instrumentSchema, instrumentSchema
-
Field Details
-
log
private static final org.slf4j.Logger log -
maxComplexity
private final int maxComplexity -
fieldComplexityCalculator
-
maxQueryComplexityExceededFunction
-
-
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
-
createState
Description copied from interface:InstrumentationThis will be called just before execution to create an object that is given back to all instrumentation methods to allow them to have per execution request state- Specified by:
createStatein interfaceInstrumentation- Overrides:
createStatein classSimplePerformantInstrumentation- Parameters:
parameters- the parameters to this step- Returns:
- a state object that is passed to each method
-
beginValidation
@Nullable public @Nullable InstrumentationContext<List<ValidationError>> beginValidation(InstrumentationValidationParameters parameters, InstrumentationState rawState) Description copied from interface:InstrumentationThis is called just before the parsed query document is validated.- Specified by:
beginValidationin interfaceInstrumentation- Overrides:
beginValidationin classSimplePerformantInstrumentation- Parameters:
parameters- the parameters to this steprawState- 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)
-
beginExecuteOperation
@Nullable public @Nullable InstrumentationContext<ExecutionResult> beginExecuteOperation(InstrumentationExecuteOperationParameters instrumentationExecuteOperationParameters, InstrumentationState rawState) 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:
instrumentationExecuteOperationParameters- the parameters to this steprawState- 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)
-
newQueryComplexityCalculator
-
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
-