Skip to content

Instantly share code, notes, and snippets.

@kirkness
Last active January 6, 2019 20:52
Show Gist options
  • Save kirkness/14d14cc5cf9d0913b2e9a1951996a5fb to your computer and use it in GitHub Desktop.
Save kirkness/14d14cc5cf9d0913b2e9a1951996a5fb to your computer and use it in GitHub Desktop.
import { createRateLimitDirective } from 'graphql-rate-limit';
const server = new ApolloServer({
typeDefs: gql`
type Mutation {
# Limit to 10 per minute
login(email: String!, password: String!): String! @rateLimit(max: 10, window: 60000)
}
`,
resolvers: {
Mutation: {
login: () => { /* ... */ }
}
},
schemaDirectives: {
rateLimit: createRateLimitDirective({
identifyContext: ctx => ctx.req.ip
})
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment