Skip to content

Commit

Permalink
types: Make initial argument to fetch required, per specification.
Browse files Browse the repository at this point in the history
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: #4741
  • Loading branch information
abernix committed Dec 31, 2020
1 parent 82caa27 commit 2351094
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-server-env/src/fetch.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Response>;

Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-server-env/src/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
declare function fetch(
input?: RequestInfo,
input: RequestInfo,
init?: RequestInit,
): Promise<Response>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
>;
}
Expand Down

0 comments on commit 2351094

Please sign in to comment.