-
Notifications
You must be signed in to change notification settings - Fork 259
feat: Support make-fetch-happen
fetcher when communicating with services
#188
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
feat: Support make-fetch-happen
fetcher when communicating with services
#188
Conversation
…make-fetch-happen fetcher
@Bhoomikapanwar: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/ |
To further add, this will ultimately help us to make |
Here is the issue I created for the same: https://github.com/apollographql/apollo-server/issues/4607 |
make-fetch-happen
fetcher when communicating with services
make-fetch-happen
fetcher when communicating with servicesmake-fetch-happen
fetcher when communicating with services
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much for tracking this down and putting this together! Very much appreciated. I've offered a couple in-line suggestions below which I'll commit before merging this, and I've made a couple tweaks to the CHANGELOG.md
, but we'll get this released soon. Relatedly, I'll also call attention to #193 (comment), since you're probably about to use make-fetch-happen
. I believe you're only suggesting you'd be relying on its timeout
behavior, but there's an important caveat around retries.
@@ -1,6 +1,6 @@ | |||
{ | |||
"name": "@apollo/gateway", | |||
"version": "0.20.4", | |||
"version": "0.21.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While we should have a "major" bump, our bumping apparatus will handle this!
"version": "0.21.0", | |
"version": "0.20.4", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a ton for picking this up so soon 👍
Moreover, Thank you for specifically pointing out the issue around retries, I absolutely agree to it. For our case, we just need timeout configurations at the moment, so it should be fine.
One more thing, do we plan to make make-fetch-happen
as the default fetcher for downstream services in this release or in the coming ones?
url: 'https://api.example.com/foo', | ||
expect(fetch).toHaveFetched('https://api.example.com/foo', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really enjoy that this pattern now matches up with the standard invocation syntax!
gateway-js/src/datasources/__tests__/RemoteGraphQLDataSource.test.ts
Outdated
Show resolved
Hide resolved
Thanks a lot for reviewing and merging it! 👍 Just to clarify, I would like to bring your attention to the following points:
You can see the reproduction setup here --> #193 (comment) After quite amount of debugging; it looks like the gateway never passes its fetcher to the RemoteGraphQLDataSource, that's why whatever fetcher configurations (default options) that we pass to the gateway are only utilised at the time of loading of schema from storage (schema registry) and are not passed down further to the services and instead RemoteGraphQLDataSource constructs its own fetcher and hence both are unrelated. In order to fix it and if we really plan to forward gateway's fetcher to RemoteGraphQLDataSource at the time of service initialisation. We'll need to do something like this;
And in case, we don't intend to do so, I think we should update the documentation for gateway to avoid any confusion around fetchers. Please let me know your thoughts on it. |
Thanks a lot @Bhoomikapanwar for fixing this. This improves resiliency of Gateway when downstream services go crazy and in turn affect the entire data graph. @abernix thank you for proactively supporting this in no time. Looking forward to getting the fix in a release. |
Released in |
Thank you for the clarity. I don't think we should make
I think my "Closing" of #193 wasn't correct in this regard. I've re-opened #193 until we can correct that.
This is actually the expected behavior right now — in that const gateway = new ApolloGateway({
buildService({ url, name }) {
return new (class extends RemoteGraphQLDataSource {
fetcher = require('make-fetch-happen').defaults();
})({
url,
name,
});
}
}); If this works, it sounds like just a documentation PR might be in order for the time-being? |
Yeah, I understand your concerns regarding making On #193, In my opinion, keeping the fetchers different for gateway and downstream services makes more sense as they have very different purposes, and applications will want in the flexibility to have different fetcher configuration for both and not worry about figuring out a set of configurations that fits both (which I think would be not really possible, for eg. for schema fetching, we'll definitely want to have caching or multiple retries but not for the downstream services) and as you said, If that's the expected behaviour right now, I think I can help with the documentation PR against the repo that you pointed out. 👍 |
The custom fetcher that the RemoteGraphQLDataSource accepts doesn't currently support make fetch happen fetcher. This PR is to add support for the same i.e add support for passing make fetch happen fetcher (any other custom fetcher other than node ) to downstream services which is required for use cases where we want to provide fetcher other than node-fetch in order to leverage functionalities provided by them.
To specifically speak of the concerned use case, our organisation wants to use a fetcher where we can configure default request options such as timeout and make fetch happen fetcher exactly fits our requirement. But with the existing codebase, passing that custom fetcher doesn't work correctly. (I debugged a lot and found the ultimate cause - which is we need the Request to be constructed by the fetcher's own Request class instead of node fetch's Request class as done currently) Hence, these are the proposed changes along with previous tests fixed and new tests added. Please look into the changes, it will really help us unblock and move forward with using Apollo gateway in production. Also, let me know if any other changes are required, I'll be happy to accommodate.
P.S. This to me feels as bug cum feature, let me know what should be correct category and I'll update the version and CHANGEME accordingly.
Thanks a ton!
Bhoomika Panwar
Closes #193
Closes #191