graphql-type-factory
Additional GraphQL types
After many fixes applied to this FORK I decided to create a separate NPM package with rewritten from scratch logic and unit tests https://www.npmjs.com/package/graphql-type
Install the package.
npm i --save graphql-type-factory
Use new types as you would use the default GraphQL types.
const {
stringFactory,
...
} = require('graphql-type-factory')
stringFactory({
name: ... Type name.
description: ... Type description.
min: ... Minimum string length.
max: ... Maximum string length.
regex: ... Regular expression pattern.
test: ... Method which returns `true` when input is valid.
});
Example:
const { stringFactory } = require('graphql-type-factory')
const Username = stringFactory({
name: 'Username',
description: 'Username for auth forms.',
min: 3,
max: 30,
regex: /^[A-Za-z0-9_]+$/,
test: (value, ast) => {
return !reservedUsernames.includes(value)
}
});
intFactory({
name: ... Type name.
description: ... Type description.
min: ... Minimum number.
max: ... Maximum number.
regex: ... Regular expression pattern (might be useful even for integers).
test: ... Method which returns `true` when input is valid.
});
Example:
const { intFactory } = require('graphql-type-factory')
const BirthDate = intFactory({
name: 'BirthDate',
min: 1870,
max: 2018
})
floatFactory({
name: ... Type name.
description: ... Type description.
min: ... Minimum number.
max: ... Maximum number.
maxDecimals: ... Maximum number of decimals.
test: ... Method which returns `true` when input is valid.
});
Example:
const { floatFactory } = require('graphql-type-factory')
const DonutPrice = floatFactory({
name: 'MyFloat',
min: 1.59,
max: 12.99,
maxDecimals: 2
})