Skip to content

RFC: Do error return values on resolvers make sense? #72

Closed
@neelance

Description

@neelance

Error handling in GraphQL seems to not be clearly defined yet. I recently started thinking about how it relates to how we do error handling in Go. Go has the clear distinction between error values and panics. The scenario I'm looking at is GraphQL used to feed data to some UI, so the "user" is the person using that UI. Here is what I've come up with:

expected unexpected
in Go returned error value panic
root cause operation failed in expected way bug in the code
error payload processed / handled only read by dev, never processed
resolution degrade gracefully or inform user fix code
in GraphQL null value or custom error field in schema "errors" list

Given this I am wondering if returning error values from resolvers actually makes sense. If it is some unexpected error, then it should be a panic. If it is something expected like "not found" or "permission denied", then it would be best to express that in the schema itself, just like we have explicit error return values in Go.

The ask for custom errors has come up several times and by saying that any error with significant payload should go into the schema itself, we would completely avoid that situation. Also the errors would then have a properly declared type schema.

It is also noteworthy that by default Relay completely discards any response that has a non-empty errors list. So if you want to pass a non-fatal error to the user in a Relay UI, then you have to use a schema field.

What are you opinions on this? Am I completely nuts? Are there other scenarios in which error values on resolvers make more sense?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions