-
-
Notifications
You must be signed in to change notification settings - Fork 821
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
Preserve source error extensions when merging schemas #1074
Conversation
Currently, when merging multiple schemas together, custom error `extensions` (like custom errors `code`'s, custom error properties, etc.) are dropped when errors are returned from child resolvers. This is caused by the current schema stitching error handling code creating copies of errors before reporting them, but not including all properties of the original error in the copy. This commit adjusts the schema stitching error handling code to preserve the `originalError` details when creating error copies. This helps `mergeSchemas` (and other parts of `graphql-tools`) include all source error `extensions`, when reporting errors through the merged schema.
These changes are available in |
Hey @hwillson, I think we need to return originalErrors here too If and when a sub resolver throws an error and some how this line it does not return an array
This works for me: KijijiCA@da27e57 |
Hey, @hwillson, it is awesome you took the job of fixing the issue. what @lucaslim referred to helped a bit. are you planning on addressing this issue too? I have created a project with a micro-services setup of merged schemas. it can be found here https://github.com/nechomer/micro-services-graphql-apollo2 |
@nechomer Just to confirm, did you try with Here's a quick repro I put together that has been updated to use Let me know if that helps - thanks! |
@hwillson , yes I did try setting package-lock with the appropriate version 5.0.0-rc.0 but it still does not work. I have opened a branch with graphql-tools@next: attached is a screenshot where it shows it is not working. |
We're dealing with this same issue, and one thing I've found is that there are 2 distinct issues, rather than just one. The first is the [object Object] problem which can be rectified by the prototype fixed called out in other tickets. The other is that if our resolver is a top level resolver, it comes through fine. It's when it's nested that it does not. So if I have query like |
@owenallenaz Could you point me in the direction of the prototype fix? Not having much fun with this and need a temporary solution. Cheers. |
https://gist.github.com/owenallenaz/d206464acae26c8612a63e0a69256e73 . This isn't a fully functional gist, since it's in a private repo, but I pulled out the meaningful sections of the code. I have only tested this in our env in which each root resolver is pulled from a remote schema. The root server's schema is just Query {} Mutation {} and then each microservice is pulled in via the links array. |
Hi @hwillson, |
Preserve source error extensions when merging schemas
Preserve source error extensions when merging schemas - Added dist folder
Preserve source error extensions when merging schemas - Fix bug
Preserve source error extensions when merging schemas - Fix bug
Thanks for tackling this @hwillson. I was playing around with this fix locally, and it only seems to maintain I have a resolver that returns an object, not an array, and return {
...object,
[ERROR_SYMBOL]: childrenErrors.map(error => ({
...error,
...(error.path ? { path: error.path.slice(1), originalError: error.originalError } : {})
}))
};
Should this be included in the PR? Thanks again! |
@benjamn I'm also interested in your opinion on my comment above, since you've got a pending review on this PR. |
Are these changes going to make it in anytime soon? |
@pcorey, the below is your code snippet above, spread across a few extra lines, with my comments:
Looks to me like your more explicit destructuring should be unnecessary. However, I imagine that is not working out? Do you have a more complete code example you could share? |
@yaacovCR You're totally right. I'm not sure what I was thinking... I'll dig into it and see if I can reproduce what I was seeing. Disregard for now. Thanks! |
@pcorey, I think you were led down the wrong path because the code changes suggested by @hwillson uses that approach in the array section above your suggested line. I think the underlying problem here was the treatment of GraphQLErrors as plain objects. Check out #1147 for a different approach -- released to graphql-tools-fork. |
Closing in favor of #1307 |
Currently, when merging multiple schemas together, custom error
extensions
(like custom errorscode
's, custom error properties, etc.) are dropped when errors are returned from child resolvers. This is caused by the current schema stitching error handling code creating copies of errors before reporting them, but not including all properties of the original error in the copy.This PR adjusts the schema stitching error handling code to preserve the
originalError
details when creating error copies. This helpsmergeSchemas
(and other parts ofgraphql-tools
) include all source errorextensions
, when reporting errors through the merged schema.This should help address:
I'm going to publish an RC for this shortly, to give people a chance to test this and provide feedback, before this is merged.