nexus-arguments-validation
TypeScript icon, indicating that this package has built-in type declarations

0.0.0-preview-1 • Public • Published

nexus-arguments-validation

nexus-arguments-validation is a Nexus plugin for arguments validation with Yup.

build downloads version

Installation

yarn add nexus-arguments-validation

Example

import { join } from 'path'
import { ApolloServer } from 'apollo-server'
import { makeSchema, mutationField, stringArg } from 'nexus'
import { object, string } from 'yup'
import { nexusArgumentsValidationPlugin } from 'nexus-arguments-validation'
 
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(),
    },
    validationSchema: ValidateUrl,
    resolve: (_, { url }) => {
      return `Your url: ${url} is valid!`
    },
  }),
]
 
const schema = makeSchema({
  types,
  plugins: [nexusArgumentsValidationPlugin()],
  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`),
)

Readme

Keywords

none

Package Sidebar

Install

npm i nexus-arguments-validation

Weekly Downloads

1

Version

0.0.0-preview-1

License

MIT

Unpacked Size

178 kB

Total Files

32

Last publish

Collaborators

  • huvik