-
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.
Make early errors more consistent and more 4xxy
There are a lot of reasons that a supposedly GraphQL request might not make it to requestPipeline: missing body, bad JSON, bad content-type, etc. Previously, many of these outcomes resulted in 5xx errors despite them being client errors (which should be 4xx), and their handling was pretty inconsistent across the integrations. Part of the confusion was a particular error message which combined "you seem to have set up your server wrong by not setting up body parsing properly" with "there was a problem parsing this request". The former is reasonable to be 500 but the latter is much more likely to be what's actually happening (you have to actively disable body parsing to make that happen!). And the recommendation was ungrammatical and express-specific despite being in apollo-server-core. But the good news is that for some reason the Express body-parser unconditionally sets `req.body` to at least `{}` before checking `content-type` (see https://github.com/expressjs/body-parser/blob/480b1cfe29af19c070f4ae96e0d598c099f42a12/lib/types/json.js#L105-L117) so we can move the "500 if body not parsed" from `apollo-server-core` to `apollo-server-express` and directly detect whether `req.body` is empty. This is a backwards-incompatible change, so we can finally implement it as v3 is imminent. The PR consists of: - Core - Make an error about needing a query be clear that it needs to be a non-empty query (the error could fire before if `query` was provided yet empty). - Make "POST body missing" error 400 instead of 500, include that it could be bad content-type or empty JSON object, and don't suggest (with poor grammar) the use of body-parser (as described above). Also show this error if httpRequest.query is a string or Buffer (this can happen with Azure Functions on JSON parse failures). - Express: Check for a sign that body-parser hasn't been applied here instead of in Core and provide a more targeted body-parser-suggesting 500. - Micro: Only parse JSON for `content-type: application/json` (like all other integrations). - Azure Functions - 400 instead of 500 for missing body - Make test more realistic on parser failures; see Core change for where this matters. Fixes #1841 (thanks to @nihalgonsalves for a good set of test cases). Fixes #4165.
- Loading branch information
Showing
17 changed files
with
216 additions
and
54 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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.