/** * * * @static * @param {any} topic * @returns * * @memberOf StorePattern */ static removeById(topic) { return { topic, cmd: 'removeById', collection: Joi.string().required(), id: Joi.alternatives() .try(Joi.number(), Joi.string()) .required() } }
/** * * * @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({}) } }
/** * * * @static * @param {any} topic * @returns * * @memberOf StorePattern */ static updateById(topic) { return { topic, cmd: 'updateById', collection: Joi.string().required(), data: Joi.object().required(), id: Joi.alternatives() .try(Joi.number(), Joi.string()) .required() } }
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) ); });
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); });
function validate(review) { const schema = { company: Joi.objectId().required(), star: Joi.number().integer().min(1).max(5).required(), title: Joi.string().min(3).max(30).required(), details: Joi.string().min(3).max(1024).required() }; return Joi.validate(review, schema); }
it('should properly create a GraphQL data type and support complex required fields', async () => { const joiSchema = object().keys({ a: number().integer().required() }); Joi2GQL.type(joiSchema)._typeConfig.fields.a.type.should.deep.equal( new GraphQLNonNull(GraphQLInt) ); });
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'), })
/** * Request Validators */ constructor() { super(); this.deleteUser = new JoiValidate({ 'params': { 'schema': Joi.object().keys({ id: Joi.number().integer().min(1).required(), }).unknown(), }, }); }
actionIndex () { return { validate: { query: { id: Joi.number().required() } } } }
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'); });
/** * * * @static * @param {any} topic * @returns * * @memberOf StorePattern */ static findById(topic) { return { topic, cmd: 'findById', collection: Joi.string().required(), id: Joi.alternatives() .try(Joi.number(), Joi.string()) .required() } }
/** * * * @static * @param {any} topic * @returns * * @memberOf StorePattern */ static replaceById(topic) { return { topic, cmd: 'replaceById', collection: Joi.string().required(), data: Joi.object().required(), id: Joi.alternatives() .try(Joi.number(), Joi.string()) .required() } }