graphql-rate-limit icon indicating copy to clipboard operation
graphql-rate-limit copied to clipboard

[QUESTION]: batch queries doesn't seem to work

Open simplecommerce opened this issue 3 years ago • 0 comments

  • I'm submitting a ... [ x ] bug report [ ] feature request [ ] question about the decisions made in the repository [ ] question about how to use this project

  • Summary

I am testing the implementation of your library in our GraphQL instance and individual mutations or queries seem to work fine for rate limiting.

But if we send batch queries or mutations, it doesn't seem to count it as individual when executing.

For example, if I send a POST to my GraphQL with the following body

[
{"operationName":"Update","variables":{}},"query":"mutation Update($input: UpdateInput!) {\n  update(input: $input)\n}\n"},
{"operationName":"Update","variables":{}},"query":"mutation Update($input: UpdateInput!) {\n  update(input: $input)\n}\n"},
{"operationName":"Update","variables":{}},"query":"mutation Update($input: UpdateInput!) {\n  update(input: $input)\n}\n"},
{"operationName":"Update","variables":{}},"query":"mutation Update($input: UpdateInput!) {\n  update(input: $input)\n}\n"},
{"operationName":"Update","variables":{}},"query":"mutation Update($input: UpdateInput!) {\n  update(input: $input)\n}\n"},
]

It only counts as 1 attempt.

I am using the resolver option implementation. What I did was put it in a middleware to run before my resolver. I also tried directly in a resolver and the same issue happens.

I might be doing something wrong. Any help is appreciated.

Update

I have tried implementing the schema option and I still get the same issue. It works for single mutations but if I send a batch using Postman, it doesn't properly count for batched requests.

I tried the following library which does the same thing https://github.com/ravangen/graphql-rate-limit and this one seems to work fine with batching.

simplecommerce avatar Jun 23 '21 14:06 simplecommerce