Adding validation to MutationOptions
See original GitHub issueInitial discussion in #160.
Validating data prior to triggering a mutation is a common (and critical) part of any action. I think it could be beneficial to add a validation
key on the MutationOptions
object that represents a method with the following signature ({ variables }) => boolean
.
View layer integrations could consume this and even add in more data to the method (like props
for React) ({ variables, ownProps }) => boolean
.
Prior to creating the mutation, this method would run (defaulting to a true
stub?) and could return an error if invalid.
Thoughts?
Issue Analytics
- State:
- Created 7 years ago
- Comments:17 (11 by maintainers)
Top Results From Across the Web
Mutations in Apollo Client - Apollo GraphQL Docs
Let's say we're creating a to-do list application and we want the user to be able to add items to their list. First,...
Read more >JavaScript - Sanity.io
client.create(doc, mutationOptions). Create a document. Argument is a plain JS object representing the document. It must contain a _type attribute.
Read more >Writing custom validations - Drupal Graphql - GitBook
You can make custom validations by implementing your own resolveOutput method inside your mutation.
Read more >Validation and User Errors in GraphQL Mutations
In this blog post I would like to propose the pattern which you can use to handle user input validation and user errors...
Read more >Validation Rules - Hot Chocolate v10 - ChilliCream
In query validation rules you can access the query and the schema but the argument ... Validation rules can be added via the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Really wish there was guidance in the docs for this. The only thing I could figure out is throwing an exception from my resolver.
Another example would be returning errors from queries - e.g. When searching for a user using graphql and getting a 404 Not found from the server.
Is there anyone who can give guidance on this?
Can’t validation errors on the server be returned from the resolver? or is that the wrong place for them?
I like the way redux-form does it’s validation which is to have a function like:
Where errors is a free form object allowing you to use errors from an ORM or client side validation library etc.