-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validations that cannot be ran on the client side and the errors object #117
Comments
+1 |
1 similar comment
+1 |
I was wondering how facebook handle error and display related error information for user with graphql? |
The data in the errors object is definitely typical for debugging. But of course the existence of an error could be used to render something in a UI about data not being available. My suggestion for the example you bring up here is to allow for data for a user-facing report in the payload of your mutation. It's often the case that mutation payloads include a The general philosophy at play is that Errors are considered exceptional. Your user data should never be represented as an Error. If your users can do something that needs to provide negative guidance, then you should represent that kind of information in GraphQL as Data not as an Error. Errors should always represent either developer errors or exceptional circumstances (e.g. the database was offline). |
Thanks @leebyron. It might be useful to spec out |
Let's say you have a uniqueness constraint on a field in a mutation. For example the
email
field must not match any existing email in the database.In graphql/graphql-js#179 it's been suggested that we shouldn't use the server to validate our forms. But in the case of our uniqueness constraint the server is the only place with enough information to determine if our form is valid.
The format of the errors response appears to be aimed at debugging. Specifically a line number is given as the only context for the error. Presumably this is so that a programmer can then use that line number to find the issue in their query/mutation. So to me the current errors array looks more analogous to a stack trace then an error object like we'd traditionally expect in a RESTful API (eg.
{"errors": {"email": ["this email has been taken"]}}
).The advantage of the error object is that we can easily match the keys in the error to the names of the fields in our form to add an error message for our users next to the offending field.
I propose that changing the errors array to an errors object would give developers access to field names and error messages in a format that is easy to map on to their forms and display to users. Eg:
Relevant Spec Section: https://facebook.github.io/graphql/#sec-Errors
The text was updated successfully, but these errors were encountered: