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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ephys/graphql-joi-directives

v1.1.1

Published

Adds Joi-powered constraint directive for GraphQL

Downloads

3

Readme

graphql-joi-directives

Add constraint validation to your GraphQL Inputs using Joi

Install

Add the package using npm i @ephys/graphql-joi-directives

This package was built with graphql-tools and supports Apollo.

Add the directives and the type definitions to your GraphQL schema:

import { joiConstraintDirectives, joiContraintDirectivesTypedefs } from '@ephys/graphql-joi-directives';

// ...

const schema = makeExecutableSchema({
  //            V this is an array
  typeDefs: [...joiContraintDirectivesTypedefs],
  schemaDirectives: {
    // V this is an object
    ...joiConstraintDirectives,
  },
});

const server = new ApolloServer({ schema });

// ...

The directives

By default, the following directives are exposed.

They can be used on fields in inputs & on arguments definitions

Strings: @str

Can be used on the String & [String] types

directive @str(
  # requires a minimum length of {min}
  min: Int,
  # requires a maximum length of {max}
  max: Int,
  # requires a length of exactly {length}
  length: Int,
  # trims the string before validation
  trim: Boolean,
  # ensure the string matches the provided regexp.
  # example
  # | pattern: "/[a-zA-Z0-9]/i"
  pattern: String,
  # requires the string to match a credit card format
  creditCard: Boolean,
  # converts casing, can be 'UPPER' or 'LOWER'
  case: JoiDirectiveCaseEnum
  # format must be a valid ISO date
  isoDate: Boolean,
  # format must be a valid ISO duration
  isoDuration: Boolean,
) on INPUT_FIELD_DEFINITION | ARGUMENT_DEFINITION

enum JoiDirectiveCaseEnum {
  UPPER
  LOWER
}

Ints: @int

Can be used on the Int & [Int] types

directive @int(
  min: Int,
  max: Int
) on INPUT_FIELD_DEFINITION | ARGUMENT_DEFINITION

Floats: @float

Can be used on the Float & [Float] types

directive @float(
  # value must be greater than or equal to {min}
  min: Float,
  # value must be less than or equal to {max}
  max: Float,
  # value must be greater than {minExclusive}
  # Joi: number.greater - https://joi.dev/api/?v=17.4.0#numbergreaterlimit
  minExclusive: Float,
  # value must be less than {maxExclusive}
  # Joi: number.less - https://joi.dev/api/?v=17.4.0#numberlesslimit
  maxExclusive: Float,
  # sets a maximum number of decimal places allowed
  precision: Int,
) on INPUT_FIELD_DEFINITION | ARGUMENT_DEFINITION

Lists: @list

Can be used on any list type

directive @list(
  # requires a minimum of {min} items in the list
  min: Int,
  # requires a maximum of {max} items in the list
  max: Int,
  # requires exactly {length} items in the list
  length: Int,
  # removes duplicate items from the list
  unique: Boolean,
) on INPUT_FIELD_DEFINITION | ARGUMENT_DEFINITION