FSharp.Data.GraphQL icon indicating copy to clipboard operation
FSharp.Data.GraphQL copied to clipboard

How to handle errors occured during the GraphQL resolver execution?

Open mistyharsh opened this issue 3 years ago • 4 comments

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

  • AddError method doesn't seem to provide any functionality.
  • Errors raised via exception are not customizable in final response.

mistyharsh avatar Aug 31 '20 10:08 mistyharsh

Is there any way to produce an error response without having to raise?

mickhansen avatar Jun 02 '21 07:06 mickhansen

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

mickhansen avatar Jun 03 '21 12:06 mickhansen

@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

xperiandri avatar Nov 05 '23 23:11 xperiandri

For exception handling see StarWarsAPI project

xperiandri avatar Nov 05 '23 23:11 xperiandri

Fixed in 2.0.0

xperiandri avatar Apr 11 '24 19:04 xperiandri