0.1.1 • Published 5 years ago
@jcm/nexus-plugin-yup-validation v0.1.1
@jcm/nexus-plugin-yup-validation
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[]
}