Apollo-feature-requests: Allow RESTDataSource to use a custom fetch function

Created on 26 Sep 2018  路  3Comments  路  Source: apollographql/apollo-feature-requests

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.

Most helpful comment

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.

All 3 comments

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FredyC picture FredyC  路  9Comments

PowerKiKi picture PowerKiKi  路  4Comments

ctretyak picture ctretyak  路  3Comments

renganatha10 picture renganatha10  路  6Comments

Vincz picture Vincz  路  3Comments