-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do I have any ways to set two rules at once ? #18
Comments
A graphql-js RFC exists to add support for repeatable directives (#1541). This is to adjust the spec's Directives Are Unique Per Location. Currently, multiple A workaround that I have been exploring in my own toy graphql-rate-limit package is to allow the same directive to be given multiple different names. For example, It's cool to see others try to tackle this problem too 👍 |
Using different names could work, however with the way the cache works you'd likely run into problems as the field calls aren't namespaced per directive name. |
Sorry, I'm a little confused. Could you write a simple example? |
This may not fully work (I didn't verify it), but outlines the idea trying to be expressed... Step 1 could be more like: const storeBurst = new InMemoryStore();
const storeSustain = new InMemoryStore();
const GraphQLRateLimitBurst = createRateLimitDirective({
store: storeBurst,
});
const GraphQLRateLimitSustain = createRateLimitDirective({
store: storeSustain,
}); The key point is you want isolation between what the directives use to keep track of usage. Having separate stores that use different prefixes could accomplish this. |
Ah, of course - yes the above should work. The key is that you have 2 separate stores. |
Cool . But if I use the default InMemoryStore I cant't do it , am I right? |
I have a another question that can we set identifyContext: ctx.user.id and ctx.req.ip or how |
Correct, the
I may be misunderstanding the question, but you can define your own const identifyContext = (ctx) => `${ctx.user.id} ${ctx.req.ip}`;
const GraphQLRateLimit = createRateLimitDirective({ identifyContext }); |
2 Do I have any ways to set two rules at once ? Just like
" course(id: Int!): Course @ratelimit(max: 5, window: "60s") @ratelimit(max: 1, window: "2s") "
but this can't work!
The text was updated successfully, but these errors were encountered: