1.0.3 • Published 8 years ago

graphql-input v1.0.3

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

Build Status

graphql-input

Validate and sanitize graphql strings and integers

install

npm install --save graphql-input

Example

const {
	constructIntType,
	constructStringType
} = require('graphql-input')

const schema = new GraphQLSchema({
	query: new GraphQLObjectType({
		name: 'query',
		description: 'test query',
		fields: {
			input: {
				type: GraphQLInt,
				description: 'Provides test integer',
				args: {
					integer: {
						type: constructIntType({
							name: 'integer',
							naturalNumber: true,
							notZero: true
						})
					}
				},
				resolve: (parentValue, {integer}) => integer
			}
		}
	})
})

API

constructIntType

const type = constructIntType({
	name: 'construct int type',
	description: 'integer',
	// validate
	naturalNumber: [boolean],	// 0 or positive integer
	notZero: [boolean],			// not 0 or -0
	min: [integer],				// minimum value
	max: [integer],				// maximum value
})

constructStringType

const type = constructStringType({
	name: 'construct string type',
	description: 'string',
	/* sanitize */
	// trim string
	trim: [boolean],
	// trim string from left side
	trimLeft: [boolean],
	// trim string from right side
	trimRight: [boolean],
	// mutate string character to lower case
	toLowerCase: [boolean],
	// mutate string character to upper case
	toUpperCase: [boolean],
	// trnucate strings lenght to specific lenght
	truncate: [integer],
	// capitalize string:
	//* 'words': every words
	//* 'sentences': every sentences
	//* 'first': first character in string
	capitalize: ['words', 'sentences', 'first']
	// regExp test for basic email format
	// advised to use with {trim = true, toLowerCase = true}
	// /^[^\s@]+@[^\s@]+\.[^\s@]+$/
	email: [boolean],
	/* validate */
	// not ""
	notEmpty: [boolean],
	// requirement for minimum strings length
	min: [integer],
	// requirement for maximum strings lenght
	max: [integer]
})
1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago