-
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 top-level errors consistent and observable (#6514)
Previously, errors that weren't specially cased as part of the "request pipeline" were not observable by plugins. (In some but not all cases, they were visible to formatError hooks.) Some "HTTP-level" errors were handled by returning text/plain responses, whereas many other errors were handled by returning GraphQL-style JSON responses (using the formatError hook). This change makes things more consistent by returning all errors as JSON responses (using the formatError hook). In addition, for better observability, several new top-level plugin APIs are introduced that are called when various kinds of errors occur. Specifically: - New plugin hook `startupDidFail`. This is called once if startup fails (eg, if a serverWillStart plugin throws or if gateway fails to load the schema). (If this hook throws, its error is logged.) Future calls to executeHTTPGraphQLRequest (if the server was started in the background) now return a formatted JSON error instead of throwing. - New plugin hook `contextCreationDidFail`. (If this hook throws, its error is logged.) As before, these errors are sent as formatted JSON errors. - New plugin hook `invalidRequestWasReceived`. This is called for all the errors that occur before being able to construct a GraphQLRequest from an HTTPGraphQLRequest; this includes things like the top-level fields being of the wrong type, missing body, CSRF failure, etc). These errors are now sent as formatted JSON instead of as text/plain. - New plugin hook `unexpectedErrorProcessingRequest`. This is called if `processGraphQLRequest` throws (typically because a plugin hook threw). We are making the assumption that this means there is a programming error, so we are making the behavior change that the thrown error will be logged and "Internal server error" will be sent in the HTTP response. - Fix grammar of "GET supports only query operation" and don't return it if the operation is unknown. Fixes #6140. Part of #6053.
- Loading branch information
Showing
11 changed files
with
497 additions
and
299 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
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.