Skip to content

Clarification Question. Errors #23

@morgz

Description

@morgz

Thanks for the great library, I've got a point of confusion I'd like help understanding.

The primary philosophy is that messages generated by invalid and/or unexpected user input are DATA, and should be returned as such. On the other hand, errors made in using an API - like querying a field that doesn’t exist -, are actually ERRORS and should be returned as errors.

are actually ERRORS and should be returned as errors.

This line confused me. Typically, my GraphQL responses have "data" and "errors" at the root. If, before passing into the build_payload function my resolution already has errors, I'm surprised they are being manipulated into the payload object and not being left as errors. That's what I though it meant by ERRORS should be returned as errors.

On the client side this gives me a bit of a problem. For example:

  • I check auth before resolving, it fails, I add an {:error, :unauthorised}
  • I look for this error on the client to refresh tokens etc.
  • On my mutations which use build_payload, these errors will get moved to messages.
  • This leaves me with 2 different checks.

My ideal would be a change like this to the library, but please feel free to tell me why it'd a bad idea!

def build_payload(%{errors: _errors} = resolution, _config), do: resolution

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