@jcm/nexus-plugin-yup-validation
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

@jcm/nexus-plugin-yup-validation

Patreon Logo
Discord Logo

This plugin allows to set a yup property on some field (Mutations are the only ones supported at the moment), and it will validate the arguments passed to the field using the given yup schema. It's inspired by something I wrote a long time ago: GraphQL Mutation Arguments Validation with Yup using graphql-middleware

Sample usage:

const AddUserMutation = mutationField((t) => {
  t.field('addUser', {
    type: AddUserPayload,
    args: {
      email: stringArg(),
    },
    yup: {
      schema: yup.object({
        email: yup.string().email().required(),
      }),
    },
    // ...
  })
})

The default errorPayloadBuilder assumes that the mutation output type has a field named error which is an object with the following structure:

{
  message: string,
  details: ErrorDetail[]
}

// ErrorDetails:
{
  path: string[],
  messages: string[]
}

Package Sidebar

Install

npm i @jcm/nexus-plugin-yup-validation

Weekly Downloads

97

Version

0.1.1

License

MIT

Unpacked Size

39.8 kB

Total Files

11

Last publish

Collaborators

  • jonathancardoso