Skip to content
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

Be able to remove the path and locations from the error object in HotChocolate V14. #7824

Open
dev-dantong-huang opened this issue Dec 13, 2024 · 2 comments

Comments

@dev-dantong-huang
Copy link

dev-dantong-huang commented Dec 13, 2024

Product

Hot Chocolate

Is your feature request related to a problem?

Hi team,

I've encountered an issue after upgrading from Hot Chocolate v13 to v14. In the project, I use an ErrorHandlingFilter (implementing IErrorFilter) to customize error responses. Previously, I could remove the path and extensions properties from the error object using methods like error.WithMessage(ex.Message).WithCode(ErrorCodes.BadUserInput).RemovePath().RemoveLocations(). This worked as expected in v13.

However, after upgrading to v14, these RemovePath() and RemoveLocations() calls no longer have any effect. The path and extensions properties are always present in the final error object.
After investigating, I found a change in MiddlewareContext.Global.cs file in v14

var errorWithPath = EnsurePathAndLocation(handled, _selection.SyntaxNode, Path);

This line seems to be re-adding the path and locations to the error, overriding the removals.

My questions are:
Is this behavior intentional in v14?
Is there a recommended way to remove path and locations from error objects in v14 if we still need it?

The solution you'd like

Be able to remove the path and locations from the error object in HotChocolate V14.

@michaelstaib
Copy link
Member

The GraphQL spec demands that field errors have a path and location. We now will always add a path to an error that is happening in a field execution context.

@michaelstaib
Copy link
Member

If an error can be associated to a particular field in the GraphQL result, it must contain an entry with the key path that details the path of the response field which experienced the error. This allows clients to identify whether a null result is intentional or caused by a runtime error.

https://spec.graphql.org/draft/#sel-HAPHRPHEByBB0Bp6Z

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants