Skip to content

dihak/nexus-args-validation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nexus-args-validation

npm version npm downloads

This plugin integrates yup into Nexus.

Installation

npm install nexus-args-validation

Example

import { join } from 'path'
import { ApolloServer } from 'apollo-server'
import { makeSchema, mutationField, stringArg } from 'nexus'
import { object, string } from 'yup'
import { nexusArgsValidation } from 'nexus-args-validation'

const types = [
  mutationField('validateUrl', {
    type: 'String',
    description: 'Validates the url argument as a valid URL via a regex',
    args: {
      url: stringArg(),
    },
    validation(yup) {
      return yup.object().shape({
        url: yup.url('Your url is not valid!'),
      })
    },
    resolve: (_, { url }) => {
      return `Your url: ${url} is valid!`
    },
  }),
]

const schema = makeSchema({
  types,
  plugins: [nexusArgsValidation()],
  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`),
)

About

This plugin integrates yup into Nexus.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published