1.2.0 • Published 6 years ago

scalars v1.2.0

Weekly downloads
8
License
MPL-2.0
Repository
github
Last release
6 years ago

scalars

GraphQL Joi Scalars

Build Status

Usage Example

const Graphi = require('graphi');
const Hapi = require('hapi');
const { JoiString } = require('scalars');

const schema = new GraphQLSchema({
  query: new GraphQLObjectType({
    name: 'RootQueryType',
    fields: {
      person: {
        type: GraphQLString,
        args: {
          username: { type: JoiString({ min: [2, 'utf8'], max: 10, alphanum: true, required: true }) },
          password: { type: JoiString({ regex: /^[a-zA-Z0-9]{3,30}$/ }) },
          email: { type: JoiString({ email: true }) }
        },
        resolve: (root, { username, password, email }, request) => {
          return Promise.resolve(firstname);
        }
      }
    }
  })
});

const server = new Hapi.Server();
server.connection();
server.register({ register: Graphi, options: { schema } }, (err) => {
  // server is ready to be started
});

Scalars

JoiAny

Supports all of the Joi Any options, passed as an object with arguments.

JoiArray

Supports all of the Joi Array options, passed as an object with arguments.

JoiBoolean

Supports all of the Joi Boolean options, passed as an object with arguments.

JoiDate

Supports all of the Joi Date options, passed as an object with arguments.

JoiNumber

Supports all of the Joi Number options, passed as an object with arguments.

JoiString

Supports all of the Joi String options, passed as an object with arguments.

Examples

const username = JoiString({ min: [2, 'utf8'], max: 10, alphanum: true, required: true });
const password = JoiString({ regex: /^[a-zA-Z0-9]{3,30}$/ });
const email =  JoiString({ email: true });
1.2.0

6 years ago

1.0.0

6 years ago

0.1.0

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago

0.0.0

7 years ago