-
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
How to return array of errors in one response? #3247
Comments
+1 |
Well it doesn't seem to be possible. After this commit error flattening was removed. 1947892 Today's code these lines forces to map from the original error array, therefore I can't think any work-around to flatten the final array from the apollo-server/packages/apollo-server-errors/src/index.ts Lines 283 to 285 in 19f0108
|
I'd like to understand what's the point of returning an error array if it's always forced to return one element. |
@gastonmorixe In what context do you mean "return an error array"? |
@glasser I want to return a flat array of isn't that nested array unnecessary? Thank you |
Sorry, to clarify, my question is the following. Is your concern:
(And I will reiterate that in the apps I've worked on, when we need a lot of complexity around errors like the ability to return lots of validations failing to be rendered in the UI, I've been happier making that an actual part of the field's return value rather than part of the out-of-band error functionality.) |
(I think if we want to do this, the best approach would be to offer a specific |
Hey @glasser thank you for your detailed and prompt response. I'd say option b. While we may agree or disagree on how errors should be handled, if the official GQL spec doesn't specify a 1-1 match between the index of the errors and the resolvers then I don't agree Apollo Server should force the devs to a nested array. At least there should be a way to opt out. I thought that was what formatError was for but it's even too late for that to help as explained above. Thank you |
I mean, I think the concern is that the mechanism we've used for expressing "resolving this path has an error" is "the resolver throws an error", and a resolver can't throw more than one error. I'd be happy to review a PR that adds an explicit way of indicating "this resolver is failing with multiple errors"; I think something like |
This actually seems like it's more appropriate for https://github.com/graphql/graphql-js than Apollo Server. There's an open issue in that repository about this: graphql/graphql-js#205 |
The response payload could contains an array of errors. Just wondering how can I simulate to return more than one errors in one response?
I'm using apollo-server in lambda and tried throw errors in two different resolvers, I added some debug console.log, those two resolvers have been executed, but one get one error in the response.
Thanks!
The text was updated successfully, but these errors were encountered: