A GraphQL validation rule that limits the total depth of incoming queries to prevent cyclical or excessively deep queries that could cause denial-of-service attacks. Version 1.1.0 is the latest stable release. Maintained as needed (no recent commits). Compared to alternatives like graphql-query-complexity or graphql-validation-complexity which assign per-field or per-type costs, this library uses a simpler depth-based metric that can catch exponential complexity growth, e.g. from repeated joins. Works with any GraphQL server that supports validation rules, such as express-graphql and koa-graphql.
npm install graphql-depth-limitNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to add graphql-depth-limit as a validation rule to an express-graphql server, limiting query depth to 10.
Consider using graphql-query-complexity for more granular cost analysis if depth alone is insufficient.
Upgrade to 1.1.0+ and pass { ignore: [ '__schema', '__type' ] } in options.Use require('graphql-depth-limit').default or switch to ESM imports.Use { ignore: ['fieldName'] } instead of a function.const depthLimit = require('graphql-depth-limit').default;Increase the limit or restructure the query to be shallower.
npm install graphql-depth-limit