npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

validate-directive

v0.6.0

Published

A GraphQL directive for input validation

Readme

validate-directive

Current Version Dependencies belly-button-style

A GraphQL directive for input validation. View the complete directive as GraphQL SDL here.

Description

GraphQL's type system provides a degree of input validation by default. However, it does not provide more fine grained validation out of the box. validate-directive provides dozens of battle-tested validation functions via a @validate directive.

@validate is a wrapper for the joi validation module. The @validate directive exposes the joi API where it makes sense. For example, joi provides validation for functions, symbols, and many other things that don't make sense in the context of a GraphQL directive.

Some joi API names are duplicated across data types. For example, in joi, min() and max() validators exist for arrays, dates, numbers, objects, etc. @validate exposes these with unique names such as arrayMax, dateMax, etc.

For questions regarding how specific joi validation functions work, see the joi documentation.

Features

  • Input validation for GraphQL primitives, enums, lists, and input objects.
  • Validation provided on input objects is inherited, and can be overridden in other locations within the schema. This allows validation to be centralized with the input type and reused.
  • The name of the directive and related input types is configurable.

Usage

enum TestEnum { A B C }

# Input objects can have schemas.
input TestInput {
  even: Int @validate(multiple: 2)

  nestedObject: [NestedTestInput!]! @validate(arrayLength: 3)
}

input NestedTestInput {
  # Enums are validated as strings.
  nestedEnum: TestEnum @validate(case: UPPER, length: { limit: 1 })
}

type Query {
  queries (
    # Boolean validation - does nothing.
    someBoolean: Boolean @validate

    # Strings and integers can be converted to dates and validated.
    dateAsString: String @validate(type: DATE, dateGreater: "1-1-1974")
    dateAsInteger: Int @validate(type: DATE, dateLess: "12-31-1973")
    isoDateString: String @validate(type: DATE, iso: TRUE)
    timestamp: Int @validate(type: DATE, timestamp: UNIX)

    # Number validation.
    greater: Float @validate(greater: 5)
    integer: Float @validate(integer: TRUE)
    less: Float @validate(less: 10)
    max: Float @validate(max: 3)
    min: Float @validate(min: -5)
    multiple: Float @validate(multiple: 2)
    negative: Float @validate(negative: TRUE)
    port: Float @validate(port: TRUE)
    positive: Float @validate(positive: TRUE)
    precision: Float @validate(precision: 2)
    sign: Float @validate(sign: NEGATIVE)
    unsafeAllowed: Float @validate(unsafe: true)
    unsafeNotAllowed: Float @validate(unsafe: false)
    doubleInteger: Int @validate(integer: TRUE)

    # String validation.
    alphanum: String @validate(alphanum: TRUE)
    base64: String @validate(base64: { paddingRequired: false })
    case: String @validate(case: UPPER)
    length: String @validate(length: { limit: 4, encoding: "utf8" })
    maxLength: String @validate(maxLength: { limit: 3, encoding: "utf8" })
    minLength: String @validate(minLength: { limit: 4, encoding: "utf8" })

    # Object validation.
    objectMaxSize: TestInput @validate(objectMax: 20)
    andRelationship: TestInput @validate(and: ["even", "nestedObject"])
    nand: TestInput @validate(nand: ["even", "nestedObject"])
    or: TestInput @validate(or: ["even", "nestedObject"])
    with: TestInput @validate(with: { key: "nestedObject", peers: ["even"] })
    without: TestInput @validate(
      without: { key: "nestedObject", peers: ["even"] }
    )
    oxor: TestInput @validate(oxor: ["even", "nestedObject"])
    xor: TestInput @validate(xor: ["even", "nestedObject"])

    # List validation.
    arrayLength: [String] @validate(case: LOWER, arrayLength: 3)
    arrayMax: [Int] @validate(arrayMax: 3)
    arrayMin: [Int] @validate(arrayMin: 1)
    sort: [TestInput] @validate(sort: { by: "even" })
    sortDescending: [TestInput] @validate(
      sort: { order: DESCENDING, by: "nestedObject.nestedEnum" }
    )
    uniqueBoolean: [Boolean] @validate(unique: {})
    uniqueObject: [TestInput] @validate(
      unique: { comparator: "nestedObject.nestedEnum" }
    )
  ): Boolean
}

type Mutation {
  validate (
    port: Int @validate(port: TRUE)
  ): Int
}