Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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'
})
}
});