/** * * * @static * @param {any} topic * @returns * * @memberOf StorePattern */ static find(topic) { return { topic, cmd: 'find', collection: Joi.string().required(), query: Joi.object().required(), options: Joi.object() .keys({ fields: Joi.alternatives().try(Joi.object(), Joi.array()), orderBy: Joi.alternatives().try(Joi.object(), Joi.array(), Joi.string()), offset: Joi.number().integer(), limit: Joi.number().integer() }) .default({}) } }
it('should properly create a GraphQL data type and support required fields', async () => { const joiSchema = object().keys({ a: number().required() }); Joi2GQL.type(joiSchema)._typeConfig.fields.a.type.should.deep.equal( new GraphQLNonNull(GraphQLFloat) ); });
function validatePage(page){ const schema = { page: Joi.number().required() } return Joi.validate(page, schema); }
it('should create a GraphQL data type and correctly set the args', async () => { const config = { name: 'Subject', args: { id: number().integer() } }; const expected = { type: typeDictionary.number }; Joi2GQL.type(internals.buildJoiSchema(), config).constructor.should.equal( GraphQLObjectType ); Joi2GQL.type(internals.buildJoiSchema(), config)._typeConfig.args.id.should.deep.equal(expected); });
// schema validation using joi static schema () { return { employeeNumber: joi.number().integer(), firstname: joi.string().alphanum().min(3).max(30).required(), lastname: joi.string().alphanum().min(3).max(30).required(), grade: joi.string().regex(/^[a-zA-Z0-9]{3}$/).required(), birthDate: joi.date().raw().required(), joinDate: joi.date().raw().required(), salary: joi.number().required(), email: joi.string().email() } }
Joi.object().keys({ id : Joi.number().integer(), firstname : Joi.string().max(128).optional(), lastname : Joi.string().max(128).optional(), created_at : Joi.date().default(() => moment().format(), 'date created'), updated_at : Joi.date().default(() => moment().format(), 'date updated'), })
it('should properly create a GraphQL data type and support int scalar types', async () => { const joiSchema = object().keys({ a: number().integer() }); Joi2GQL.type(joiSchema)._typeConfig.fields.a.type.should.equal( GraphQLInt ); });
it('should assign name to Anon if one was not given', async () => { const joiSchema = object().keys({ a: string(), b: number().integer() }); Joi2GQL.type(joiSchema).name.should.equal('Anon'); });
actionIndex () { return { validate: { query: { id: Joi.number().required() } } } }
get isNumber () { return Joi.number().required() }