Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(executor): argument value parsing errors should return 400 #4827

Merged
merged 4 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/thin-countries-tan.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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