Open pi0neerpat opened 3 years ago
@pi0neerpat Thanks for taking this on -- in fact after @dac09 and I implemented the Validator and Transformer directives, I realized that "traditional" directives might collide -- but then I realized, maybe not!
I hoped (but did not confirm) that since the directive in the schema -- which is declared by the plugin -- is neither a Validator or Transformer:
I hoped that the useRedwoodDirective
would just let it work as normal.
But regardless:
@rateLimit(max: Int, window: String, message: String)
You can pass in arguments. They are available as the directiveArgs
:
That's how requireAuth can look at the roles.
As for Redis, have a look at ioredis.
I used it to implement the responseCache for Redis here:
Also, have you seen the redis store provided by rate-limiter?
https://github.com/teamplanes/graphql-rate-limit/blob/master/src/lib/redis-store.ts
Howdy, I'm almost done implementing rate limiting using the envelop plugin. Wanted to start throwing together docs for this so others can use them.
Todo:
Docs for using @envelop/rate-limiter
First install the necessary packages:
Generate the
rateLimit
directive, and choose "Validator" when prompted:We'll need to make a few changes to the directive, so it can accept arguments:
Then add the directive to your SDLs e.g.:
Since our function is serverless, we need to keep in mind that using memory store is probably not the best idea. Instead, let's use Redis to manage our IP address logging. Create a redis entity:
Lastly, add the plugin to the graphql server, and specify the
store
option to use our Redis instance: