Validation rule for GraphQL query complexity analysis to protect against resource exhaustion and DoS attacks. Current stable version is 1.1.0. The library is actively maintained by Slicknode and works with graphql-js v15 and v16. Key differentiators: supports multiple estimators (simple, directive, field extensions, custom), allows per-field cost calibration, and integrates as a validation rule into existing GraphQL servers.
npm install graphql-query-complexityNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a query complexity validation rule and applies it to a GraphQL document. The rule limits total query complexity to 1000 with each field costing 1 by default.
Upgrade graphql peer dependency to v15 or v16.
Always provide at least one estimator (e.g., simpleEstimator) to avoid runtime errors.
Ensure all estimators return a number or implement proper error handling. Use simpleEstimator as a catch-all.
Always pass the query variables object (can be empty: {}).Update import to use 'createComplexityRule'.
Add at least one estimator (e.g., simpleEstimator) in the 'estimators' array.
Pass a variables object (e.g., {}) in the configuration.Increase maximumComplexity or reduce query depth/complexity via schema design.
Upgrade graphql to v15 or v16.