FSharp.Data.GraphQL
FSharp.Data.GraphQL copied to clipboard
How to handle errors occured during the GraphQL resolver execution?
Description
Error handling documentation is missing/not very clear. I found AddError method on Context object but it does not seem to produce any result.
Repro steps
As the title of the issue suggest, how to properly handle errors? The error is described here in detail on stackoverflow.
Expected behavior
Ideally I would like to generate errors as:
{
"documentId": 1234,
"data": {
"login": null
},
// The errors array is not available
"errors": [
{ message: "error description", code: 1001, path: "" }
]
}
Actual behavior
AddErrormethod doesn't seem to provide any functionality.- Errors raised via exception are not customizable in final response.
Is there any way to produce an error response without having to raise?
ctx.AddError plus middleware that adds the errors to the response works decently, but you lose path.
It'd be great to have path exposed in ResolveFieldContext
@mistyharsh now you can return IGQLError interface optionally implementing IGQLErrorExtensions interface to attach extensions according to specification.
Aslo, you get very detailed errors out of the box now. See #440
For exception handling see StarWarsAPI project
Fixed in 2.0.0