A GraphQL rate limiter library (v3.3.0) that adds basic but granular rate limiting to GraphQL queries and mutations. Works with any Node.js GraphQL setup via three approaches: as a schema directive (@rateLimit), as a graphql-shield rule, or as a base rate limiter function for custom integration. Supports custom stores (Redis, Postgres, Mongo, in-memory default), identity extraction from context, configurable time windows and max requests, and custom error messages. Written in TypeScript, requires Node >=12 and graphql as a peer dependency. Differentiators include simplicity (no complex middleware), flexibility (multiple integration patterns), and first-class TypeScript support.
npm install graphql-rate-limitNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to create a rate limit directive and apply it to a field using @graphql-tools/schema.
Always provide identifyContext in instance config.
Use formatError: (identity, context, fieldConfig) => new Error('Custom message').For production, provide a custom store (e.g., Redis via ioredis) in instance config.
Use import syntax or dynamic import() in CommonJS projects.
Add identifyContext: (ctx) => ctx.user?.id ?? ctx.ip when calling createRateLimitDirective, createRateLimitRule, or getGraphQLRateLimiter.
If using graphql-tools with schemaDirectives, ensure you are using the correct version or use the new schemaTransforms approach.
Run 'npm install graphql-rate-limit'. Ensure your tsconfig.json includes 'node' moduleResolution.