Skip to content
This repository has been archived by the owner on Mar 20, 2023. It is now read-only.

Response with form validation errors #12

Closed
xpepermint opened this issue Sep 19, 2015 · 2 comments
Closed

Response with form validation errors #12

xpepermint opened this issue Sep 19, 2015 · 2 comments

Comments

@xpepermint
Copy link

Let's say you have a <form> which posts data to API server. The API server validates the input and returns JSON object. If the input is invalid (e.g. invalid email or email already exists in database) an error objects {errors: {email: "already exists"}} is returned.
How do we handle and serve these kind of errors when using GraphQL? How and where should data validation be implemented (should that be part of my GraphQL code, maybe inside each resolve function)?

@leebyron
Copy link
Contributor

This is a bit outside the scope of the express plugin, and there is a good discussion of input validation here: graphql/graphql-js#44

To answer your question briefly, yes resolve functions are a great place to put this kind of validation and error detection logic.

@xpepermint
Copy link
Author

@leebyron Thanks! That link helped and I managed to create a helper library https://github.com/xpepermint/graphql-type-factory.

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

No branches or pull requests

2 participants