-
Notifications
You must be signed in to change notification settings - Fork 2k
How to correctly throw an Error in Apollo 4 custom plugin hooking into "requestDidStart"? #7375
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
Comments
Is throwing from your context function an option? We made the behavior of doing that well-defined in AS4. |
@glasser Yes, in this case this would be possible, because it's a error which can be catched before the lifecycle even starts. But I've also other plugins which might throw errors (query complexity etc.) and can't be catched outside the gql processing. And I'm afraid I'll run into the same issue there, right? |
I mentioned in #7278 (comment) why this is a bit challenging w.r.t. error handling in this particular early handler. On the other hand we do make sure that throwing from |
Yes, you're right @glasser. The header check issue was resolved by doing it in the context creation function, and as you say, query complexity happens later in So my issues are solved. Thx for your support! |
In Apollo 3, I was able to throw an Error if there was missing a header I enforce to be present, and the Error got correctly passed into the response to the client:
Now while migrating to Apollo 4, I've changed to code to the new structure:
but this leads to the following response to the client:
response.
Any ideas how to correctly throw an Error in this case? I tried for hours now but can't find a solution for this. The docs don't cover throwing Errors in Plugins (as far as I saw).
The text was updated successfully, but these errors were encountered: