0.3.0 • Published 6 months ago

graphql-validate-directive v0.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

graphql-validate-directive

npm GitHub Workflow Status Codecov Snyk Vulnerabilities for npm package

Summary

This is a directive validation library for GraphQL. Inspired by validate-directive.

Different with graphql-constraint-directive. It do validate on resolve field instead of creating new scaler.

Installation

yarn add graphql-validate-directive

or

npm i -S graphql-validate-directive

Usage

Use in the project.

import {
  validateDirective,
  GraphQLValidateDirectiveTypeDefs,
} from 'graphql-validate-directive'
import { makeExecutableSchema } from '@graphql-tools/schema'

const schema = makeExecutableSchema({
  typeDefs: [
    // ... your type definitions
    GraphQLValidateDirectiveTypeDefs,
  ],
  resolvers: {
    // ...
  },
})

validateDirective()(schema)

Use in schema.

# used on input field
input PostInput {
  title: String! @validate(minLength: 1, maxLength: 1000)
  content: String! @validate(minLength: 1, maxLength: 1000)

  # used on array
  tags: [String!]
    @validate(minItems: 1, maxItems: 10, minLength: 1, maxLength: 100)
}

type Mutation {
  createPost(input: PostInput!): Post

  # used on argument
  createMessage(
    content: String! @validate(minLength: 1, maxLength: 200)
  ): Message
}

License

MIT Licensed.

0.3.0

6 months ago

0.2.0

1 year ago

0.1.8

1 year ago

0.1.9

1 year ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago