-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[BUG] fix: add missing await to catch errors thrown in parsingDidEnd() #6559
Conversation
✅ Deploy Preview for apollo-server-docs canceled.Built without sensitive environment variables
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 06c258f:
|
Ooh, great catch. The larger issue is hopefully already improved on the |
I don't think this change is harmful in any way (so I won't push to revert), but I also don't think it solves the issue. If that hook throws, the catch block should still hit whether the function call is awaited or not (somebody please correct me if I'm wrong, this would be very surprising to me). What I think is actually happening is this: I suspect the |
I think you're both right: If the non-error call to #6567 would fix the odd behavior of "hook can be called twice", and version-4 already handles unexpected errors being thrown from plugins better. That said, it sounds like you are intentionally throwing from parsingDidEnd, and expecting that to render as a particular kind of error. I'm not sure that our code attempts to make that be a supported thing, and version-4 will make that worse by changing the error to be an "unexpected error got thrown" error. ie, it seems like you're using this as some sort of validation stage? Perhaps you want to specify custom |
@glasser There's a particular category of query errors (invalid queries) where a operation name ( I am sure you know this but adding it here for context regardless: When sending multiple named operations in a single document , you have to also pass a A few days ago our backend api was under attack with someone trying to penetrate the graphql api with arbitrary (invalid) requests. We normally "ignore" invalid user input (4xx errors) in our alerting stack (these types of attack attempts happen regularly) but because this one actually made it past the query validation into the plugin stage and some of the plugins expected a valid The logic in apollo-server/packages/apollo-server-core/src/requestPipeline.ts Lines 293 to 304 in 54416e2
We have a plugin (custom query complexity) that requires additional context from the requests and therefore can't be used with the bare Hence why we chose to do this in the However, during that (while debugging In order to prevent that, we also added another Apollo plugin to capture these errors (invalid operation) and throw them as SyntaxErrors at the That resolves it for us, but the better approach (imho this is currently a bug) would be to actually throw a SyntaxError in apollo-server/packages/apollo-server-core/src/requestPipeline.ts Lines 293 to 296 in 54416e2
|
Note that the TypeScript types for So yeah... It all comes down to resolving the |
Related to that: The |
Thanks for all the details! Here are some thoughts. Note that "AS4" means "Apollo Server 4, in active development on the
|
Well that all sounds great :-). So I consider this "resolved" for us. I added a TODO in our codebase to remove our "hotfix" once AS4 lands. Thanks for the detailed response. |
Currently, errors throwing during the post-parsing phase hook fly by this try/catch block because of the missing await. They then bubble up into the outer scope and are treated as INTERNAL_SERVER_ERRORS. This took me quite a while to figure out (hard to spot that missing
await
there).There are also other incidents in this code base where errors are incorrectly thrown as INTERNAL_SERVER_ERROR where they should instead be BAD_USER_INPUT (e.g. missing
query
). Maybe something you'd want to fix too?Thanks!