• Stars
    star
    101
  • Rank 338,166 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

!!!Checkout new TypeScript rewrite version with some breaking changes

joonhocho/graphql-scalar

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.

More Repositories

1

tsdef

TypeScript common pattern shortcut definitions / utility gist library
TypeScript
591
star
2

tscpaths

Replace absolute paths to relative paths after typescript compilation
TypeScript
266
star
3

react-native-google-sign-in

React Native Wrapper for Latest Google Sign-In OAuth SDK / API
Objective-C
211
star
4

graphql-rule

GraphQL rule / access control / auth / security / authorization / permission
JavaScript
157
star
5

react-native-linkedin-sdk

React Native Wrapper for Latest LinkedIn Mobile SDK for Sign-In / Auth and API Access.
Objective-C
40
star
6

batchloader

BatchLoader is a utility for data fetching layer to reduce requests via batching written in TypeScript. Inspired by Facebook's DataLoader. Works great with GraphQL, MongoDB, Mongoose, etc.
TypeScript
35
star
7

firebase-encode

Encode and decode firebase key string to escape and unescape unsafe characters (.$[]#/).
JavaScript
34
star
8

proptypes-parser

PropTypes parser / generator for React and React Native components with GraphQL-like syntax.
JavaScript
29
star
9

react-native-mail-compose

React Native library for composing email. Wraps MFMailComposeViewController for iOS and Intent for Android.
Java
27
star
10

react-native-message-compose

React Native library for composing Message / SMS / Text. Wraps MFMessageComposeViewController for iOS and Intent for Android.
Java
24
star
11

graphql-scalar

Configurable custom GraphQL Scalars (string, number, date, etc) with sanitization / validation / transformation in TypeScript.
TypeScript
23
star
12

vcard-generator

VCard v4.0 rfc6350 compliant generator from JSON.
JavaScript
21
star
13

graphql-input-string

A configurable custom input string type for GraphQL with sanitization and validation.
JavaScript
20
star
14

graphql-relay-connection

A GraphQL Relay connection with cursor based on any comparator. Can be used with ObjectId for MongoDB.
JavaScript
20
star
15

seri

JavaScript (Node.js) serializer / deserializer with support for classes.
JavaScript
19
star
16

tsapis

Various cloud services API response types documented and written in TypeScript
TypeScript
16
star
17

country-calling-code

Country calling codes based on countrycode.org
JavaScript
15
star
18

react-native-router-relay-todo

React Native Todo App with react-router-native and relay
JavaScript
10
star
19

auth0-react-native

React Native port of Auth0 SDK (auth0/auth0.js)
JavaScript
10
star
20

react-hat

A higher order component for react-helmet that auto fills favicon, og, twitter meta tags for SEO.
JavaScript
9
star
21

s3-policy-v4

Amazon AWS S3 Upload Policy Generator with Signature Version 4
JavaScript
8
star
22

angular-smart-scroll

Smart infinite scroll directive for Angular.js that is customizable to support nested, horizontal, vertical, and/or bidirectional scrolls
JavaScript
7
star
23

underscore-node

Underscore for Node.js without unnecessary cross-browser checks
JavaScript
7
star
24

romodel

A lightweight and unopinionated model-based data accessor / enhancer library
JavaScript
6
star
25

ts-jutil

TypeScript library of simple utility functions
TypeScript
6
star
26

graphql-fetcher

A GraphQL data fetcher using fetch API.
JavaScript
5
star
27

iso-country-codes

ISO Country Codes including Alpha-2, Alpha-3, and numeric codes
JavaScript
5
star
28

jexgrid

JavaScript Grid Solution
JavaScript
4
star
29

react-native-contact-picker

React Native wrapper for CNContactPickerViewController
Swift
4
star
30

rn-json-store

A thin wrapper around React Native's AsyncStorage to easily write and read JSON values.
JavaScript
4
star
31

graphql-complexity

Compute complexity of GraphQL Queries
JavaScript
3
star
32

basex-encoder

Encode / decode any base X to and from string or buffer written in TypeScript
TypeScript
3
star
33

jwt-node-decoder

Decodes JWT (JSON Web Token) and checks expiration date. A Node port of angular-jwt.
JavaScript
2
star
34

auth-perm

A simple level-based permission / authorization / access control
JavaScript
2
star
35

angular-facebook-api

A Facebook SDK wrapper service for Angular.js
JavaScript
2
star
36

fullcontact-card-reader

FullContact Card Reader API Wrapper for Node.js
JavaScript
2
star
37

firestore-backup-cronjob

TypeScript
2
star
38

s3-policy-middleware

Express Middleware for Amazon AWS S3 Upload Policy Generator with Signature Version 4
JavaScript
2
star
39

servertil

HTTP server / express related utilities library written in TypeScript
TypeScript
1
star
40

material-design-color-palette

Material design color palette meets TinyColor
JavaScript
1
star
41

tsxhr

A super lightweight XMLHTTPRequest wrapper written in TypeScript. No dependencies.
TypeScript
1
star
42

healthcheck-ok

A simple healthcheck middleware for express.js that sends 200.
JavaScript
1
star
43

tstf

CLI tools for useful TypeScript code transformations such as paths transforms.
TypeScript
1
star
44

restpi

REST API client for various third party cloud services
TypeScript
1
star
45

superwild

Extremely fast, optimized, compilable wildcard pattern matching without using RegExp, which is slow.
TypeScript
1
star
46

webtil

Tiny utility library functions to be used in browser written in TypeScript
TypeScript
1
star
47

sanidator

Sanitize and Validate JavaScript Objects
JavaScript
1
star
48

unagi

A collection of basic JavaScript utility functions intended for Node.js (V8). It is best optimized for performance with NO cross-browser compatibility.
JavaScript
1
star
49

formost

Event based reactive form field model
TypeScript
1
star
50

react-native-add-contact

WIP: NOT WORKING YET! Add contact to address book
Java
1
star
51

vcard3

vCard 3.0 iOS compliant
TypeScript
1
star
52

react-native-issues-solutions

This repo is for me to track current React Native issues and possible/best available solutions.
1
star
53

firestore-model

Firestore / Firebase object model schema wrapper
TypeScript
1
star
54

expjson

Super lightweight, fast, and optimized evaluate-able and compilable expressions in JSON written in TypeScript
TypeScript
1
star
55

ga-util

Google Analytics Wrapper written in TypeScript
TypeScript
1
star
56

ts-url

URL object parser written in TypeScript
TypeScript
1
star
57

brands

social media brands / branding resources
1
star
58

tshttpcode

HTTP Status Code enum in TypeScript optimized for tree shaking
TypeScript
1
star
59

swifty-js

Swift like property observer (willSet, didSet) pattern for JavaScript.
JavaScript
1
star
60

memprop

React optimization tool for memoizing (function / object) property to avoid unnecessary re-renders
TypeScript
1
star
61

blitline-s3

Post Blitline jobs that uploads to s3 and do polling for the jobs.
JavaScript
1
star
62

notil

Small utility library written in TypeScript to be used in Node.js environment using Node packages.
TypeScript
1
star
63

smartystreets-js

JS client for SmartyStreets API. Address autocomplete and verification.
JavaScript
1
star