🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

graphql-validate-directive

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-validate-directive

A GraphQL directive for input validation

0.1.9
Source
npm
Version published
Weekly downloads
85
26.87%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Keywords

graphql

FAQs

Package last updated on 28 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts