-
-
Notifications
You must be signed in to change notification settings - Fork 565
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
Why are error results thrown? #704
Comments
That behaviour seems like it might be a leftover from porting the I tried to disable the re-throwing and found that it causes 21 tests to fail. |
Ok seems to be something deeply nested within |
Yeah, you can return exceptions from resolvers, not just throw them.
There are several use-cases where this is useful. One is when you use lists: "resolve" => function () {
return [
"item1",
new MyException("Error with item2"),
"item3",
];
} The other is when some parent resolver decides that a field must be an error: "resolve" => function () {
return [
'title' => 'My Title',
'secureContent' => new MyException("You can't read this"),
];
} If this exception occurs in a nullable field - this field is replaced with I guess you could just wrap your custom exceptions to work around this OR use a non-throwable class for such errors. Another potential solution is to utilize the Closing this as answered but feel free to follow-up if you have questions. |
In my current application I have a fixed number of common exceptions that might occure while resolving a mutation.
To handle this scenario I have created a UnionType combining the expected ObjectResultType and several ErrorResultTypes.
I thought I could catch the exceptions in a try-catch block within the resolver and then pass them down to resolveType, but unexpectedly Throwable results are thrown again .
Why is this behaviour important?
The text was updated successfully, but these errors were encountered: