-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New error extension
http
for setting status/headers in context, res…
…olvers (#6857) You can now add a `Partial<HTTPGraphqlHead>` as an `http` error extension, which provides an easier way of setting HTTP response headers or status codes. These are honored when thrown from resolvers and `context` functions (and are also used internally to implement bad request errors etc). Multiple resolver errors can have `http` extensions to set status code and distinct headers separately; we do not commit to the semantics of what happens if multiple errors set the status code or set the same header. Now that you have more control over `context` error handling, simplify the default behavior: if the error thrown from `context` is not a `GraphQLError` with an `http` extension with a `status`, the default status code is 500 rather than sometimes being 400 based on `extensions.code`. Only prepend `Context creation failed: ` to the error message if the error is not already a GraphQLError. This still keeps the helpful message for developers while allowing you to remove it if you don't want it to be visible in your app. Fixes #6140. Fixes #5636. Fixes #6840. Co-authored-by: Rose M Koron <[email protected]>
- Loading branch information
Showing
13 changed files
with
577 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@apollo/server-integration-testsuite": patch | ||
"@apollo/server": patch | ||
--- | ||
|
||
Errors thrown in resolvers and context functions can use `extensions.http` to affect the response status code and headers. The default behavior when a context function throws is now to always use status code 500 rather than comparing `extensions.code` to `INTERNAL_SERVER_ERROR`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.