From 235109497e96042bee6fffcc7b6522378057ea5a Mon Sep 17 00:00:00 2001 From: Jesse Rosenberger Date: Thu, 31 Dec 2020 12:15:46 +0000 Subject: [PATCH 1/2] types: Make initial argument to `fetch` required, per specification. The first argument to the `fetch` method from the Fetch API is not meant to be optional, per the specification (linked in the references below). I'm also unaware of any implementation where all parameters are optional, so even if there is a case where it could be something different than what was specified here, we should probably change the type to be something more concrete since passing _no_ options at all seems undesirable. While I'm not certain why it was optionalized in the original types, changing it to be required will hopefully be unobtrusive because of the aforementioned reasons. Moreso, since these are typing changes only, releasing this change will not cause runtime surprises, but rather type errors at compilation type. Please open an issue if you discover an incompatibility in a project that cannot be easily resolved! Ref: https://fetch.spec.whatwg.org/#fetch-method Ref: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API Fixes: https://github.com/apollographql/apollo-server/issues/4741 --- CHANGELOG.md | 1 + packages/apollo-server-env/src/fetch.d.ts | 2 +- packages/apollo-server-env/src/global.d.ts | 2 +- .../src/make-fetch-happen.d.ts | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 96148915319..cbd3e7c5412 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ The version headers in this history reflect the versions of Apollo Server itself > The changes noted within this `vNEXT` section have not been released yet. New PRs and commits which introduce changes should include an entry in this `vNEXT` section as part of their development. With few exceptions, the format of the entry should follow convention (i.e., prefix with package name, use markdown `backtick formatting` for package names and code, suffix with a link to the change-set à la `[PR #YYY](https://link/pull/YYY)`, etc.). When a release is being prepared, a new header will be (manually) created below and the appropriate changes within that release will be moved into the new section. - `apollo-server-express`: types: Export `ExpressContext` from main module. [PR #4821](https://github.com/apollographql/apollo-server/pull/4821) [Issue #3699](https://github.com/apollographql/apollo-server/issues/3699) +- `apollo-server-env`: types: The first parameter to `fetch` is now marked as required, as intended and in accordance with the Fetch API specification. [PR #TODO]() [Issue #4741](https://github.com/apollographql/apollo-server/issues/4741) ## v2.19.1 diff --git a/packages/apollo-server-env/src/fetch.d.ts b/packages/apollo-server-env/src/fetch.d.ts index 6d138daea2b..04932f68b14 100644 --- a/packages/apollo-server-env/src/fetch.d.ts +++ b/packages/apollo-server-env/src/fetch.d.ts @@ -2,7 +2,7 @@ import { Agent as HttpAgent } from 'http'; import { Agent as HttpsAgent } from 'https'; export declare function fetch( - input?: RequestInfo, + input: RequestInfo, init?: RequestInit, ): Promise; diff --git a/packages/apollo-server-env/src/global.d.ts b/packages/apollo-server-env/src/global.d.ts index 82813030cb7..ed81ff60d9d 100644 --- a/packages/apollo-server-env/src/global.d.ts +++ b/packages/apollo-server-env/src/global.d.ts @@ -1,5 +1,5 @@ declare function fetch( - input?: RequestInfo, + input: RequestInfo, init?: RequestInit, ): Promise; diff --git a/packages/apollo-server-plugin-operation-registry/src/make-fetch-happen.d.ts b/packages/apollo-server-plugin-operation-registry/src/make-fetch-happen.d.ts index 6b7f1737a10..f2290fa301a 100644 --- a/packages/apollo-server-plugin-operation-registry/src/make-fetch-happen.d.ts +++ b/packages/apollo-server-plugin-operation-registry/src/make-fetch-happen.d.ts @@ -46,7 +46,7 @@ declare module 'make-fetch-happen' { * @see: https://git.io/JvBwX */ export interface Fetcher { - (input?: RequestInfo, init?: RequestInit & FetcherOptions): Promise< + (input: RequestInfo, init?: RequestInit & FetcherOptions): Promise< Response >; } From acf2613dd97d05507d33fce68c2622edfbec2354 Mon Sep 17 00:00:00 2001 From: Jesse Rosenberger Date: Thu, 31 Dec 2020 15:02:19 +0200 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbd3e7c5412..6c28b1bb14a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ The version headers in this history reflect the versions of Apollo Server itself > The changes noted within this `vNEXT` section have not been released yet. New PRs and commits which introduce changes should include an entry in this `vNEXT` section as part of their development. With few exceptions, the format of the entry should follow convention (i.e., prefix with package name, use markdown `backtick formatting` for package names and code, suffix with a link to the change-set à la `[PR #YYY](https://link/pull/YYY)`, etc.). When a release is being prepared, a new header will be (manually) created below and the appropriate changes within that release will be moved into the new section. - `apollo-server-express`: types: Export `ExpressContext` from main module. [PR #4821](https://github.com/apollographql/apollo-server/pull/4821) [Issue #3699](https://github.com/apollographql/apollo-server/issues/3699) -- `apollo-server-env`: types: The first parameter to `fetch` is now marked as required, as intended and in accordance with the Fetch API specification. [PR #TODO]() [Issue #4741](https://github.com/apollographql/apollo-server/issues/4741) +- `apollo-server-env`: types: The first parameter to `fetch` is now marked as required, as intended and in accordance with the Fetch API specification. [PR #4822](https://github.com/apollographql/apollo-server/pull/4822) [Issue #4741](https://github.com/apollographql/apollo-server/issues/4741) ## v2.19.1