@winninjs/graphql-io-utils
v1.5.0
Published
Utilities directives and scalar types to help on graphql input/output validation and sanitization.
Downloads
7
Readme
graphql-io-utils
Utilities directives and scalar types to help on graphql input/output validation and sanitization.
Installation
npm i @winninjs/graphql-io-utils
Scalar
Represents a valid email
type Query{
email:Email! # Returns a non-null valid Email
sendEmail(email:Email):Email # Send and returns a valid Email
}
URL
Represents a valid URL
type Query{
url:URL! # Returns a non-null valid URL
sendURL(url:URL):URL # Send and returns a valid URL
}
PII
Redacts PII info on string
type Query{
piiData:PII! # Returns a redacted PII string
}
Directives
It includes two directives:
@stringUtils
Lets you run a method over a string input or output
type Query{
returnTrimmedAndUpper:String! @stringUtils(stringMethods:["trim","toUpperCase"]) # runs trim and toUpperCase on returned String
sendTrimmedAndLower(trimmedAndLower:String!@stringUtils(stringMethods:["trim","toLowerCase"])):String! # runs trim and toLowerCase on query argument
}
@validate
Runs common validations over input
type Query{
email(value:String! @validate(email:true)):String! #validates if the value is an valid email
}
Currently supports the following validations:
- url
- alpha
- alphaNum
- alphaDash
- digits
- ip
- hex
- lt
- lte
- gt
- gte
- stringLengthLT
- stringLengthLTE
- stringLengthGT
- stringLengthGTE
- stringLengthEquals
- notEmpty
- startsWith
- endsWith
- contains
- notContains