Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/huv1k/nexus-arguments-validation
https://github.com/huv1k/nexus-arguments-validation
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/huv1k/nexus-arguments-validation
- Owner: huv1k
- License: mit
- Created: 2020-01-31T11:59:09.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T16:24:01.000Z (almost 2 years ago)
- Last Synced: 2024-05-29T23:33:45.619Z (6 months ago)
- Language: TypeScript
- Size: 1.06 MB
- Stars: 10
- Watchers: 2
- Forks: 1
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - nexus-arguments-validation
README
nexus-arguments-validation
`nexus-arguments-validation` is a [Nexus](https://github.com/prisma-labs/nexus) plugin for arguments validation with [Yup](https://github.com/jquense/yup).
![build](https://github.com/huv1k/nexus-arguments-validation/workflows/Build%20and%20test/badge.svg)
[![downloads](https://img.shields.io/npm/dt/nexus-arguments-validation.svg)](https://npmjs.org/package/nexus-arguments-validation?cacheSeconds=3600)
[![version](https://img.shields.io/npm/v/nexus-arguments-validation.svg)](https://npmjs.org/package/nexus-arguments-validation?cacheSeconds=3600)## Installation
```bash
yarn add nexus-arguments-validation
```## Example
```typescript
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`),
)
```