Tools
Tools: Introducing graphql-complexity-validation
2026-01-19
0 views
admin
✨ Features ## 📦 Installation ## 🧠 How it works ## 🧪 Example ## 🔗 Links GraphQL is powerful, but without limits, complex queries can easily overwhelm your server. That’s why I built graphql-complexity-validation:
a lightweight, framework-agnostic GraphQL validation rule that limits query complexity using native GraphQL validation. Each field has a cost (default: 1).
Nested fields accumulate cost recursively.
If the total exceeds the configured maximum, validation fails. No directives.
No schema traversal.
No framework lock-in. Feedback, issues, and contributions are welcome 🙌
If you find it useful, please consider starring the repo ⭐ Templates let you quickly answer FAQs or store snippets for re-use. Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well For further actions, you may consider blocking this person and/or reporting abuse COMMAND_BLOCK:
npm install graphql-complexity-validation Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
npm install graphql-complexity-validation COMMAND_BLOCK:
npm install graphql-complexity-validation CODE_BLOCK:
createComplexityLimitRule({ maxComplexity: 20, fieldCosts: { posts: 3, comments: 2, },
}); Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
createComplexityLimitRule({ maxComplexity: 20, fieldCosts: { posts: 3, comments: 2, },
}); CODE_BLOCK:
createComplexityLimitRule({ maxComplexity: 20, fieldCosts: { posts: 3, comments: 2, },
}); - Zero runtime dependencies
- Fully typed (TypeScript)
- Supports fragments & inline fragments
- Introspection ignored by default
- Works with: Apollo Server
GraphQL Yoga
Envelop
NestJS
- Apollo Server
- GraphQL Yoga - Apollo Server
- GraphQL Yoga - npm: https://www.npmjs.com/package/graphql-complexity-validation
- GitHub: https://github.com/Mateodiaz401/graphql-complexity-validation
how-totutorialguidedev.toaiservergitgithub