@envelop/rate-limiter
10.1.0
Minor Changes
-
#4530
62c2cd1Thanks @enisdenjo ! - Field config now accepts anidentifiertemplate string as a lightweight alternative toidentifyFnSupports
{args.argName}and{context.propName}dot-path interpolation, equivalent to using@rateLimit(identityArgs: [...])via the directive but available in programmatic config.useRateLimiter({ identifyFn: ctx => ctx.ip, configByField: [ { type: 'Query', field: 'getProduct', window: '1m', max: 10, identifier: '{args.id}' }, { type: 'Query', field: 'search', window: '1m', max: 30, identifier: '{context.ip}' } ] }) -
#4530
62c2cd1Thanks @enisdenjo ! -identifyFnnow receives field argument values as a second parameter when used viaconfigByFieldThe per-field
identifyFnonConfigByFieldreceives the resolved argument values, making it straightforward to rate limit unauthenticated requests by argument value without a directive.useRateLimiter({ identifyFn: ctx => ctx.ip, configByField: [ { type: 'Query', field: 'getProduct', // getProduct(id: ID!): Product! window: '1m', max: 10, identifyFn: (ctx, args) => String(args.id) } ] })Note: the root
identifyFnalso receives args as a second parameter when it acts as the fallback for aconfigByFieldentry, but args will be empty when it is invoked for directive-based rate limiting.