Apollo-datasource-rest rate limit

Hi,

I was hoping someone would have an answer to this question.

Does the apollo-datasource-rest package handle rate limits?
How does it do that?

Or how do you guys manage this using this package?

If I have an API endpoint that has a rate limit, how would I specify it in the datasource if possible?

Any help or guidance is appreciated, thanks!

AFAIK there are no rate limiting features provided by RestDataSource itself - either the backend remote services could do this (by returning HTTP 429’s to REST calls) or rate limiting should be thought about in terms of use of GraphQL queries & mutations rather than any backend services.

There are several npm packages that offer this kind of feature than can be integrated with Apollo server e.g. rate-limiter-flexible - npm, graphql-rate-limit-directive - npm

Hope this helps!

1 Like

Thank you for your reply!

I am already using one of the rate limiter packages for mutations which works well.

The reason I was asking about the limiter, was because my GraphQL server sends API requests to an emailer service in order to send emails that are dispatched.

It is a result of a mutation but since I can’t predict how many concurrent users might hit this mutation at a time, I was hoping to hear how people handle this.

I just thought about this, would a setTimeout work?
Maybe I can add a setTimeout with await before sending the actual request.

I also noticed that there are 2 packages to handle rest API’s, which ones do people generally use?

or