Introducing graphql-complexity-validation

Published: (January 19, 2026 at 01:39 PM EST)
1 min read
Source: Dev.to

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,
  },
});
  • npm:
  • GitHub:

Feedback, issues, and contributions are welcome 🙌
If you find it useful, please consider starring the repo ⭐

Back to Blog

Related posts

Read more »

Just released podpdf

!Cover image for Just released podpdfhttps://media2.dev.to/dynamic/image/width=1000,height=420,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s...