Skip to content

Commit 8962d40

Browse files
committed
chunk
1 parent 9d6ae6e commit 8962d40

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

packages/server/src/errorNormalize.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
import { ApolloServerErrorCode } from './errors/index.js';
99
import type { HTTPGraphQLHead } from './externalTypes/http.js';
1010
import {
11-
isHTTPGraphQLHead,
11+
HeaderMap,
1212
mergeHTTPGraphQLHead,
1313
newHTTPGraphQLHead,
1414
} from './runHttpQuery.js';
@@ -68,8 +68,11 @@ export function normalizeAndFormatErrors(
6868
ApolloServerErrorCode.INTERNAL_SERVER_ERROR,
6969
};
7070

71-
if (isHTTPGraphQLHead(extensions.http)) {
72-
mergeHTTPGraphQLHead(httpFromErrors, extensions.http);
71+
if (isPartialHTTPGraphQLHead(extensions.http)) {
72+
mergeHTTPGraphQLHead(httpFromErrors, {
73+
headers: new HeaderMap(),
74+
...extensions.http,
75+
});
7376
delete extensions.http;
7477
}
7578

@@ -98,3 +101,12 @@ export function ensureGraphQLError(maybeError: unknown): GraphQLError {
98101
? error
99102
: new GraphQLError(error.message, { originalError: error });
100103
}
104+
105+
function isPartialHTTPGraphQLHead(x: unknown): x is Partial<HTTPGraphQLHead> {
106+
return (
107+
!!x &&
108+
typeof x === 'object' &&
109+
(!('status' in x) || typeof (x as any).status === 'number') &&
110+
(!('headers' in x) || (x as any).headers instanceof Map)
111+
);
112+
}

packages/server/src/runHttpQuery.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -248,16 +248,6 @@ export function newHTTPGraphQLHead(status?: number): HTTPGraphQLHead {
248248
};
249249
}
250250

251-
export function isHTTPGraphQLHead(x: unknown): x is HTTPGraphQLHead {
252-
return (
253-
!!x &&
254-
typeof x === 'object' &&
255-
(!('status' in x) || typeof (x as any).status === 'number') &&
256-
'headers' in x &&
257-
(x as any).headers instanceof Map
258-
);
259-
}
260-
261251
// Updates `target` with status code and headers from `source`. For now let's
262252
// consider it undefined what happens if both have a status code set or both set
263253
// the same header.
@@ -268,7 +258,9 @@ export function mergeHTTPGraphQLHead(
268258
if (source.status) {
269259
target.status = source.status;
270260
}
271-
for (const [name, value] of source.headers) {
272-
target.headers.set(name, value);
261+
if (source.headers) {
262+
for (const [name, value] of source.headers) {
263+
target.headers.set(name, value);
264+
}
273265
}
274266
}

0 commit comments

Comments
 (0)