Skip to content

Commit 0c2c8d3

Browse files
committed
More type safe upload terminating Apollo Link request handler code.
1 parent 7e6d4ef commit 0c2c8d3

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

UploadHttpLink.mjs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ export default class UploadHttpLink extends ApolloLink {
134134
"",
135135
);
136136

137+
/**
138+
* URI for the GraphQL request.
139+
* @type {string}
140+
*/
137141
let uri = selectURI(operation, fetchUri);
138142

139143
if (files.size) {
@@ -179,11 +183,16 @@ export default class UploadHttpLink extends ApolloLink {
179183
options.method = "GET";
180184

181185
if (options.method === "GET") {
182-
const { newURI, parseError } = rewriteURIForGET(uri, body);
186+
const result =
187+
/** @type {{ newURI: string } | { parseError: unknown }} */ (
188+
// The return type is incorrect; `newURI` and `parseError`
189+
// will never both be present.
190+
rewriteURIForGET(uri, body)
191+
);
183192

184-
if (parseError) throw parseError;
193+
if ("parseError" in result) throw result.parseError;
185194

186-
uri = newURI;
195+
uri = result.newURI;
187196
} else options.body = JSON.stringify(clone);
188197
}
189198

changelog.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
### Patch
3131

3232
- Avoid the deprecated Apollo Link HTTP utility function `createSignalIfSupported`.
33-
- Moved all the upload terminating Apollo Link request handler code into a single constructed `Observer` that’s returned regardless of errors.
33+
- Improved the upload terminating Apollo Link request handler code:
34+
- Moved all of it into a single constructed `Observer` that’s returned regardless of errors.
35+
- More type safe.
3436
- Updated the package scripts:
3537
- Reordered and renamed scripts.
3638
- Replaced `npm run` with `node --run`.

0 commit comments

Comments
 (0)