Search code examples
graphqlrelayjsgraphql-js

User input validation with Relay


From the looks of it, it seems that the best way to do validation with Relay is to use custom GraphQL scalar types in your schema. Is this so?


Solution

  • You should think of this as being analogous to server-side type validation with a REST API.

    While you can validate scalar data that way, this code runs on the server rather than the client, and it's equivalent to e.g. a REST backend rejecting a request with a 400.

    In practice, for ideal UX, you probably want to do some of this validation on the client side to offer more feedback (and more immediate feedback) when practical.