We have a practice of wrapping HTTP calls to other internal services in Circuit Breakers. This is very easy to do with HTTPLink since it takes a fetch function as an option. However, looking into using DataSources there doesn't seem to be any way of achieving something equivalent with RESTDataSource. The call to fetch happens inside the HTTPCache class which always imports the same global fetch function.
It would be really helpful not only for implementing circuit breakers but I'm sure other specifics to be able to configure RESTDataSource with a custom fetch function.
This could be helpful, I did find that most features of node-fetch work, timeout etc,
mentioned here: https://github.com/apollographql/apollo-server/issues/1594
But I realize that may not solve it completely. If passing a custom client, It would just need to be fully compatible with node-fetch to avoid breaking things, otherwise the next easiest solution is make a custom version of RESTDataSource.
Yeah the use case I'm thinking of is applying decorators to node-fetch to add functionality like retries, rate-limiting, circuit breaking, etc.
We absolutely could make our own custom version of RESTDataSource but we figured it might just be a generally useful thing and we could submit a PR.
https://github.com/apollographql/apollo-server/pull/1807 has been merged. This feature will be coming in the next AS release. Thanks very much @jbachhardie!
Most helpful comment
Yeah the use case I'm thinking of is applying decorators to
node-fetchto add functionality like retries, rate-limiting, circuit breaking, etc.We absolutely could make our own custom version of RESTDataSource but we figured it might just be a generally useful thing and we could submit a PR.