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.

Only single validation sent to client at a time

See original GitHub issue

Bug report

  • I have checked other issues to make sure this is not a duplicate.

Describe the bug

Note: not sure if this is a bug or working as intended.

Consider a validation like this:

inputRule((yup) => {
  return yup.object({
    email: yup.required(),
    username: yup.required(),
    password: yup.required(),
  })
})

If I invoke the graphql mutation that uses this yup validation, with no input arguments, I will only see one validation error at a time. This makes it difficult to build a nice user experience on things like login forms, etc, since the user will only see one issue at a time.

Expected behavior

I expect the graphql api to return three validations, ideally with the path to the property associated with each validation error. Something along the lines of “email is required”, “username is required”, and “password is required”.

Actual behaviour

Only one validation at a time is returned.

Additional context

This behavior can be controlled on the yup side of things via the abortEarly validation option, e.g. yup.validate(schema, { abortEarly: false }).

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
maticzavcommented, Oct 24, 2019

🎉 This issue has been resolved in version 7.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

1reaction
maticzavcommented, May 23, 2019

Hey 👋,

Excuse my absence, I had my final examinations, but I am up and running now. I have done some experimentation and I propose the following. inputRule should be extended so that it exposes options which will include all available Yup options.

Furthermore, we should somehow enable the possibility of manipulating the errors list returned by Yup since I cannot find a better default alternative. I have attached an example of error object and its complement on GraphQL side below so you get the idea of the data that we are dealing with.

ValidationError {
      name: 'ValidationError',
      value: { email: 'notemail' },
      path: undefined,
      type: undefined,
      errors: [ 'It has to be an email!', 'password is a required field' ],
      inner:
       [ ValidationError {
           name: 'ValidationError',
           value: 'notemail',
           path: 'email',
           type: undefined,
           errors: [Array],
           inner: [],
           message: 'It has to be an email!',
           params: [Object] },
         ValidationError {
           name: 'ValidationError',
           value: undefined,
           path: 'password',
           type: 'required',
           errors: [Array],
           inner: [],
           message: 'password is a required field',
           params: [Object] } ],
      message: '2 errors occurred' }

GraphQLError {
           message: '2 errors occurred',
           locations: [Array],
           path: [Array] } ]

Perhaps you have any idea how we could make this more approachable?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Validate only one field at a time · Issue #512 · jaredpalmer/formik
Validation starts work only after first press submit button. So user can safely filling Fields, and he get error messages only after trying...
Read more >
Input Validation on Client-Side or Server-Side? - Packetlabs
Using server-side validation indicates that any input sent by the user (or client) cannot be trusted.
Read more >
How to respond to different validation errors at the server side?
I have done quiet a lot of research on how to validate a form submission and understand that it is necessary to implement...
Read more >
Input Validation: Client-Side & Server-Side Cybersecurity ...
Client -side validation exists on the front-end and is part of the front-end secure coding requirements. It responds faster to the user's input ......
Read more >
Client-side form validation - Learn web development | MDN
This is called client-side form validation, and helps ensure data submitted matches the requirements set forth in the various form controls.
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