By default the HotChocolate GraphQL server does not expose any exception details when an errors occurs. The only information you get back is the following:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"errors": [ | |
{ | |
"message": "Unexpected Execution Error" | |
} | |
] | |
} |
This is of course a good idea from a security endpoint but not very helpful when you want to investigate a problem.
In order to automatically add exception details to your GraphQL error you can switch the execution option to include exception details:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services.AddGraphQLServer() | |
.ModifyRequestOptions(o => | |
{ | |
// 👇 Include Exception Details on the development environment | |
o.IncludeExceptionDetails = _environment.IsDevelopment(); | |
o.Complexity.Enable = true; | |
o.Complexity.MaximumAllowed = 250; | |
}); |
Remark: When a debugger is attached this behavior is changed automatically and exception details are included.
More information: Error Filter - Hot Chocolate - ChilliCream GraphQL Platform