Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphql-input-number

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-input-number

A configurable custom input number type for GraphQL with sanitization and validation.

  • 0.0.9
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.1K
decreased by-11.17%
Maintainers
2
Weekly downloads
 
Created
Source

graphql-input-number

Build Status Coverage Status npm version Dependency Status License

A configurable custom input number type for GraphQL with sanitization and validation.

Checkout graphql-input-string for validating string inputs.

Install

npm install --save graphql-input-number

Usage

import {
  GraphQLInputInt,
  GraphQLInputFloat,
} from 'graphql-input-number';

const argType = GraphQLInputInt({
  name: 'OneToNineInt',
  min: 1,
  max: 9,
});

new GraphQLObjectType({
  name: 'Query',
  fields: {
    input: {
      type: GraphQLInt,
      args: {
        number: {
          type: argType,
        },
      },
      resolve: (_, {number}) => {

        // 'number' IS AN INT BETWEEN 1 to 9.

      };
    },
  },
});

Options

GraphQLInputInt({
  // Type name.
  // [REQUIRED]
  name: string = null,

  // Sanitize function that is called at the end of sanitzation phase and before
  // validation phase.
  sanitize: ((number) => number) = null,

  // Minimum value allowed (inclusive).
  min: number = null,

  // Maximum value allowed (inclusive).
  max: number = null,

  // Test function that is called at the end of validation phase.
  test: ((number) => boolean) = null,

  // Custom error handler.
  // May throw an error or return a value.
  // If a value is returned, it will become the final value.
  error: ErrorHandler = () => throw GraphQLError,

  // Parse function that is called after validation phase before returning a
  // value.
  // May throw an error or return a value.
  parse: ((number) => any) = null,

  // If you want to pass some config to type constructor, simply add them here.
  // For example,
  description: string,
});

GraphQLInputFloat({
  ...same as GraphQLInputInt
});


type ErrorInfo = {
  type: string,
  value: number,
  message: ?string,
  ast: ?Ast,
  ...args,
};


type ErrorHandler = (ErrorInfo) => any;

License

The MIT License (MIT)

Copyright (c) 2016 Joon Ho Cho

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Keywords

FAQs

Package last updated on 23 Jan 2017

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc