A fixed window rate-limiting directive for GraphQL schemas (v2.0.6). It wraps resolvers to enforce per-field or per-object rate limits using a declarative @rateLimit directive. Supports multiple backends (Redis, in-memory via rate-limiter-flexible), custom key generation, and response extensions. Requires graphql ^16.0.0, @graphql-tools/utils ^8-10, and rate-limiter-flexible ^2-5. Differentiated by its directive-based approach and TypeScript support.
npm install graphql-rate-limit-directiveNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a GraphQL server with @rateLimit directive limiting Query.hello to 10 calls per 60 seconds.
Use import syntax; configure Node.js for ESM ("type": "module" in package.json) or use dynamic import().Replace import { rateLimitDirectiveTypeDefs, rateLimitDirectiveTransformer } with const { ... } = rateLimitDirective();Upgrade graphql to ^16.0.0 and rate-limiter-flexible to ^2.0.0 || ^3.0.0 || ^4.0.0 || ^5.0.0
Ensure keyGenerator returns a string (e.g., String(context.ip)).
Adopt makeExecutableSchema from @graphql-tools/schema or wrap the transformer accordingly.
Use 'points' configuration to associate costs; ensure resolver failure doesn't consume points.
Configure rateLimiterFactory to return an instance of RateLimiterRedis from rate-limiter-flexible.
Run npm install graphql-rate-limit-directive and ensure all peer dependencies are installed. For ESM, add "type": "module" to package.json.
Use: const { rateLimitDirectiveTransformer } = rateLimitDirective();Ensure keyGenerator always returns a string, e.g., keyGenerator: (context) => context.req.ip ?? 'anonymous'
Add rateLimitDirectiveTypeDefs to the typeDefs array in makeExecutableSchema.
Ensure rate-limiter-flexible is ^2.0.0 || ^3.0.0 || ^4.0.0 || ^5.0.0 and matches the version used in the package lock.