nexus-plugin-arguments-validation
v0.0.0-preview-4
Published
```bash yarn add nexus-plugin-arguments-validation ```
Downloads
157
Readme
nexus-plugin-arguments-validation
is a Nexus plugin for arguments validation with Yup.
Installation
yarn add nexus-plugin-arguments-validation
Example
import { join } from 'path'
import { ApolloServer } from 'apollo-server'
import { makeSchema, mutationField, stringArg } from '@nexus/schema'
import { object, string } from 'yup'
import { argumentsValidationPlugin } from 'nexus-plugin-arguments-validation/schema'
const ValidateUrl = object().shape({
url: string().url('Your url is not valid!'),
})
const types = [
mutationField('validateUrl', {
type: 'String',
description: 'Validates the url argument as a valid URL via a regex',
args: {
url: stringArg(),
},
// @ts-ignore
validateArgs: ValidateUrl,
resolve: (_, { url }) => {
return `Your url: ${url} is valid!`
},
}),
]
const schema = makeSchema({
types,
plugins: [argumentsValidationPlugin()],
outputs: {
schema: join(__dirname, 'generated/schema.graphql'),
typegen: join(__dirname, 'generated/nexus.ts'),
},
})
new ApolloServer({
schema,
}).listen({ port: 4000 }, () =>
console.log(`🚀 Server ready at: http://localhost:4000`),
)