Skip to content

Commit

Permalink
feat(executor): argument value parsing errors should return 400 (#4827)
Browse files Browse the repository at this point in the history
* feat(executor): argument value parsing errors should return 400

* Satisfy v15

* Go

* Go
  • Loading branch information
ardatan committed Nov 7, 2022
1 parent 1270b75 commit c0639dd
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/thin-countries-tan.md
@@ -0,0 +1,5 @@
---
'@graphql-tools/utils': minor
---

TypeError and all other GraphQLError s from argument value parsing should return 400
45 changes: 42 additions & 3 deletions packages/executor/src/execution/execute.ts
Expand Up @@ -230,7 +230,20 @@ export function execute<TData = any, TVariables = any, TContext = any>(

// Return early errors if execution context failed.
if (!('schema' in exeContext)) {
return { errors: exeContext };
return {
errors: exeContext.map(e => {
Object.defineProperty(e, 'extensions', {
value: {
...e.extensions,
http: {
...e.extensions?.['http'],
status: 400,
},
},
});
return e;
}),
};
}

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

// Return early errors if execution context failed.
if (!('schema' in exeContext)) {
return { errors: exeContext };
return {
errors: exeContext.map(e => {
Object.defineProperty(e, 'extensions', {
value: {
...e.extensions,
http: {
...e.extensions?.['http'],
status: 400,
},
},
});
return e;
}),
};
}

const resultOrStream = createSourceEventStreamImpl(exeContext);
Expand Down Expand Up @@ -1348,7 +1374,20 @@ export function createSourceEventStream(

// Return early errors if execution context failed.
if (!('schema' in exeContext)) {
return { errors: exeContext };
return {
errors: exeContext.map(e => {
Object.defineProperty(e, 'extensions', {
value: {
...e.extensions,
http: {
...e.extensions?.['http'],
status: 400,
},
},
});
return e;
}),
};
}

return createSourceEventStreamImpl(exeContext);
Expand Down

0 comments on commit c0639dd

Please sign in to comment.