Documentation
¶
Overview ¶
Package limits provides reusable gqlgen extensions for enforcing abuse-resilient GraphQL execution limits.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RequestComplexityLimit ¶ added in v1.6.19
func RequestComplexityLimit(ctx context.Context, configuredComplexity int, automationComplexity int) int
RequestComplexityLimit resolves the complexity limit for the authenticated caller. Human and anonymous callers retain the operator-configured limit; automation callers retain a bounded, independently-configurable limit even when the general limit is disabled. Complexity remains the primary resource-consumption control and is intentionally per-profile.
func RequestDepthLimit ¶ added in v1.6.4
RequestDepthLimit resolves the depth limit for the authenticated caller. Human and anonymous callers retain the operator-configured limit; automation callers retain a bounded, independently-configurable limit even when the general limit is disabled. Depth is a coarse structural bound: query complexity, parser-token, and pagination limits remain the primary breadth and resource-consumption controls.
Types ¶
type ComplexityLimit ¶ added in v1.6.19
type ComplexityLimit struct {
Func func(ctx context.Context, opCtx *graphql.OperationContext) int
// contains filtered or unexported fields
}
ComplexityLimit enforces a maximum query complexity for a GraphQL operation. A per-request limit resolved by Func of <= 0 disables complexity enforcement for that request, mirroring DepthLimit's semantics.
func (ComplexityLimit) ExtensionName ¶ added in v1.6.19
func (c ComplexityLimit) ExtensionName() string
ExtensionName implements graphql.HandlerExtension.
func (ComplexityLimit) MutateOperationContext ¶ added in v1.6.19
func (c ComplexityLimit) MutateOperationContext(ctx context.Context, opCtx *graphql.OperationContext) *gqlerror.Error
MutateOperationContext implements graphql.OperationContextMutator.
func (*ComplexityLimit) Validate ¶ added in v1.6.19
func (c *ComplexityLimit) Validate(schema graphql.ExecutableSchema) error
Validate implements graphql.HandlerExtension.
type ComplexityStats ¶ added in v1.6.19
type ComplexityStats struct {
// Complexity is the calculated complexity for this request.
Complexity int
// ComplexityLimit is the limit for this request returned by the extension func.
ComplexityLimit int
}
ComplexityStats contains computed complexity information for the active GraphQL operation.
func GetComplexityStats ¶ added in v1.6.19
func GetComplexityStats(ctx context.Context) *ComplexityStats
GetComplexityStats returns ComplexityStats for the active operation, if available.
type DepthLimit ¶
type DepthLimit struct {
Func func(ctx context.Context, opCtx *graphql.OperationContext) int
}
DepthLimit enforces a maximum selection depth for a GraphQL operation.
Depth is defined as the maximum number of nested field selections from the operation root. If a query exceeds the configured limit, a 422 status code will be returned by gqlgen.
func FixedDepthLimit ¶
func FixedDepthLimit(limit int) *DepthLimit
FixedDepthLimit sets a depth limit that does not change. A limit <= 0 disables depth enforcement.
func (DepthLimit) ExtensionName ¶
func (d DepthLimit) ExtensionName() string
ExtensionName implements graphql.HandlerExtension.
func (DepthLimit) MutateOperationContext ¶
func (d DepthLimit) MutateOperationContext(ctx context.Context, opCtx *graphql.OperationContext) *gqlerror.Error
MutateOperationContext implements graphql.OperationContextMutator.
func (*DepthLimit) Validate ¶
func (d *DepthLimit) Validate(_ graphql.ExecutableSchema) error
Validate implements graphql.HandlerExtension.
type DepthStats ¶
DepthStats contains computed depth information for the active GraphQL operation.
func GetDepthStats ¶
func GetDepthStats(ctx context.Context) *DepthStats
GetDepthStats returns DepthStats for the active operation, if available.