question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding validation to MutationOptions

See original GitHub issue

Initial 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:closed
  • Created 7 years ago
  • Comments:17 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
ryannealmescommented, Nov 25, 2016

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?

2reactions
ciwolseycommented, May 4, 2016

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:

(values) => {
  const errors = {};
  if(values.category !== 'news') errors.category = "Category must be news";
  return errors;
}

Where errors is a free form object allowing you to use errors from an ORM or client side validation library etc.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found