function createDepthLimitRule
createDepthLimitRule(
maxDepth: number,
GraphQLError: new (message: string) => GraphqlGraphQLErrorLike
): (context: ValidationRuleContext) => DepthLimitVisitor

Create a validation rule that limits query depth.

A validation rule is a function that receives a validation context and returns a visitor object. The visitor object has methods for different AST node kinds that are called during traversal.

The return type is written out rather than inferred: this function is part of the package's public API, and JSR rejects an inferred return type there ("slow types") because it blocks automatic .d.ts generation for Node.

Parameters

maxDepth: number

Maximum allowed depth (0 to disable)

GraphQLError: new (message: string) => GraphqlGraphQLErrorLike

The GraphQLError constructor to use for creating errors

Return Type

(context: ValidationRuleContext) => DepthLimitVisitor

A validation rule function (receives context, returns visitor)

Usage

import { createDepthLimitRule } from "graphql-plugin/src/index.ts";