0.1.0 • Published 10 years ago
graphql-type-factory v0.1.0
graphql-type-factory
Additional GraphQL types
Setup
Install the package.
npm i --save graphql-type-factoryUse new types as you would use the default GraphQL types.
import { ... } from 'graphql-type-factory'; // ES6
var GraphQLTypeFactory = require('graphql-type-factory'); // CommonJSTypes
::: String Factory
GraphQLStringFactory({
name: ... Type name.
min: ... Minimum string length.
max: ... Maximum string length.
regex: ... Regular expression pattern.
fn: ... Method which returns `true` when input is valid.
});Example:
var NameType = GraphQLStringFactory({
name: 'Name',
fn: function(ast) {return ast.value.length > 5}
});GraphQLEmailType::: URL
GraphQLURLTypeExample
How to run the example:
- Clone this repository.
- Run
npm installto install the required modules. - Run
npm run exampleto start the GraphQL server. - Create a new user.
curl -XPOST -H 'Content-Type:application/graphql' -d 'mutation RootMutation { addUser(id: "1", name: "John", email: "me@domain.com", website: "http://domain.com")}' http://localhost:4444- Retrieve created users.
curl -XPOST -H 'Content-Type:application/graphql' -d '{users{id, email}}' http://localhost:4444