Skip to content
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

Add example of server-side validation failure #357

Closed
cesarandreu opened this issue Sep 19, 2015 · 4 comments
Closed

Add example of server-side validation failure #357

cesarandreu opened this issue Sep 19, 2015 · 4 comments

Comments

@cesarandreu
Copy link

Not sure if this belongs here or graphql-relay-js.

If you have validation that can only be done on the server, it's not clear how you can notify the client and how to handle it.

I asked about this in Reactiflux and someone pointed out I can throw in mutateAndGetPayload, and handle it in the onFailure callback of update.

Having a small server-side failure example would be really helpful.

@u9520107
Copy link

If you throw in mutateAndGetPayload, the errors will be sent to the browser.
But currently in the onFailure callback, transaction.getError() will return the errors in a string.
If you have multiple errors, their error messages will be listed out.

Come to think about it, this is rather inconvenient if we want to address those errors differently.
Or if I simply want to send an error code and display some error message in the language of the browser.
I think having a way to access the error objects separately is better. This may even allow us to provide more data to the client-side if necessary.

@mmurray
Copy link

mmurray commented Sep 20, 2015

@u9520107 transaction.getError() actually returns an error object. And it seems you can get an array of the individual errors from transaction.getError().source.errors.

@steveluscher
Copy link
Contributor

This is great discussion. Can we get this on Stack Overflow as a question, where it will endure long after this issue is closed?

https://stackoverflow.com/questions/ask?tags=relayjs

If you think there's something better Relay could be doing here, feel free to open a separate issue with a suggestion.

@rterysen-openroad
Copy link

@cesarandreu Would love a snippet or a more detailed example of handing server side validation. I see tons of examples of relay but none are geared towards real world scenarios.

http://stackoverflow.com/questions/38706347/relay-mutation-with-serverside-validation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants