Introducing graphql-complexity-validation
Source: Dev.to
✨ Features
- Zero runtime dependencies
- Fully typed (TypeScript)
- Supports fragments & inline fragments
- Introspection ignored by default
Works with
- Apollo Server
- GraphQL Yoga
- Envelop
- NestJS
📦 Installation
npm install graphql-complexity-validation
🧠 How it works
- Each field has a cost (default: 1).
- Nested fields accumulate cost recursively.
- If the total exceeds the configured maximum, validation fails.
Additional notes
- No directives.
- No schema traversal.
- No framework lock‑in.
🧪 Example
createComplexityLimitRule({
maxComplexity: 20,
fieldCosts: {
posts: 3,
comments: 2,
},
});
🔗 Links
- npm:
- GitHub:
Feedback, issues, and contributions are welcome 🙌
If you find it useful, please consider starring the repo ⭐