How to use the graphql-rate-limit.createRateLimitRule function in graphql-rate-limit

To help you get started, we’ve selected a few graphql-rate-limit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github teamplanes / graphql-rate-limit / example / index.js View on Github external
RedisStore,
  getGraphQLRateLimiter,
  createRateLimitRule
} = require('graphql-rate-limit');
const redis = require('redis');

// Option 1: Use a directive (applied in the schema below)
const rateLimitDirective = createRateLimitDirective({
  identifyContext: context => {
    return context.req.ip;
  },
  store: new RedisStore(redis.createClient())
});

// Option 2: User graphql-shield (applied in the `shield` below)
const rateLimit = createRateLimitRule({
  formatError: () => {
    return 'Stop doing that so often.';
  },
  identifyContext: context => {
    return context.req.ip;
  }
});

const permissions = shield({
  Query: {
    myId: rateLimit({
      max: 2,
      window: '10s'
    })
  }
});

graphql-rate-limit

Add Rate Limiting To Your GraphQL Resolvers 💂‍♀

MIT
Latest version published 3 years ago

Package Health Score

53 / 100
Full package analysis

Similar packages