INNER CODE UNIT · TypeScript

rateLimitDirective

ravangen/graphql-rate-limit · src/index.ts:251

export function rateLimitDirective<
  TContext,
  TLimiterOptions extends IRateLimiterOptions = IRateLimiterOptions,
>({
  name = 'rateLimit',
  defaultLimit = '60',
  defaultDuration = '60',
  keyGenerator = defaultKeyGenerator,
  pointsCalculator = defaultPointsCalculator,
  onLimit = defaultOnLimit,
  setState,
  limiterClass = RateLimiterMemory,
  limiterOptions = <TLimiterOptions>{},
}: RateLimitOptions<TContext, TLimiterOptions> = {}): RateLimitDirective {
  const limiters = new Map<string, RateLimiterAbstract>();
  const getLimiter = ({ limit, duration }: RateLimitArgs): RateLimiterAbstract => {
    const limiterKey = `${limit}/${duration}s`;
    let limiter = limiters.get(limiterKey);

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…