Skip to content

Commit c0639dd

Browse files
authored
feat(executor): argument value parsing errors should return 400 (#4827)
* feat(executor): argument value parsing errors should return 400 * Satisfy v15 * Go * Go
1 parent 1270b75 commit c0639dd

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

.changeset/thin-countries-tan.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-tools/utils': minor
3+
---
4+
5+
TypeError and all other GraphQLError s from argument value parsing should return 400

packages/executor/src/execution/execute.ts

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,20 @@ export function execute<TData = any, TVariables = any, TContext = any>(
230230

231231
// Return early errors if execution context failed.
232232
if (!('schema' in exeContext)) {
233-
return { errors: exeContext };
233+
return {
234+
errors: exeContext.map(e => {
235+
Object.defineProperty(e, 'extensions', {
236+
value: {
237+
...e.extensions,
238+
http: {
239+
...e.extensions?.['http'],
240+
status: 400,
241+
},
242+
},
243+
});
244+
return e;
245+
}),
246+
};
234247
}
235248

236249
return executeImpl(exeContext);
@@ -1256,7 +1269,20 @@ export function subscribe<TData = any, TVariables = any, TContext = any>(
12561269

12571270
// Return early errors if execution context failed.
12581271
if (!('schema' in exeContext)) {
1259-
return { errors: exeContext };
1272+
return {
1273+
errors: exeContext.map(e => {
1274+
Object.defineProperty(e, 'extensions', {
1275+
value: {
1276+
...e.extensions,
1277+
http: {
1278+
...e.extensions?.['http'],
1279+
status: 400,
1280+
},
1281+
},
1282+
});
1283+
return e;
1284+
}),
1285+
};
12601286
}
12611287

12621288
const resultOrStream = createSourceEventStreamImpl(exeContext);
@@ -1348,7 +1374,20 @@ export function createSourceEventStream(
13481374

13491375
// Return early errors if execution context failed.
13501376
if (!('schema' in exeContext)) {
1351-
return { errors: exeContext };
1377+
return {
1378+
errors: exeContext.map(e => {
1379+
Object.defineProperty(e, 'extensions', {
1380+
value: {
1381+
...e.extensions,
1382+
http: {
1383+
...e.extensions?.['http'],
1384+
status: 400,
1385+
},
1386+
},
1387+
});
1388+
return e;
1389+
}),
1390+
};
13521391
}
13531392

13541393
return createSourceEventStreamImpl(exeContext);

0 commit comments

Comments
 (0)