scalars

1.2.0 • Public • Published

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 });

/scalars/

    Package Sidebar

    Install

    npm i scalars

    Weekly Downloads

    22

    Version

    1.2.0

    License

    MPL-2.0

    Unpacked Size

    33.6 kB

    Total Files

    6

    Last publish

    Collaborators

    • wyatt