it('should properly create a GraphQL data type and support list scalar types', async () => { const joiSchema = object().keys({ a: array().items(string()) }); Joi2GQL.type(joiSchema)._typeConfig.fields.a.type.should.deep.equal( new GraphQLList(GraphQLString) ); });
all(args) { const result = API_CALL_ARRAY.validate(args[0], { presence: 'required' }); if (result.error) { throw new APIError(result.error.message); } for (const apiCall of args[0]) { exports.validate(apiCall.name, apiCall.args || []); } }
it('should properly construct a graphql data type given a recursive felicity constructor nested in an array', async () => { const config = { name : 'Subject', args : { id: number().integer() }, resolve: function () {} }; const joiSchema = object().keys({ a: string(), b: number().integer(), c: number(), d: object().keys({ prop1: string(), prop2: string() }), e: boolean(), f: array().items(lazy(() => joiSchema).description('Subject')) // May not need users to specify }); Joi2GQL.type(joiSchema, config).constructor.should.equal( GraphQLObjectType ); });
const getValidation = (resource, method) => { switch (method) { case GET: return { query: { limit: Joi.number().integer(), page: Joi.number().integer(), ids: Joi.array().items(Joi.objectId()).single(), }, }; case PATCH: return { params: { id: Joi.objectId() }, payload: Schemas[resource][method], }; case POST: return { payload: Schemas[resource][method] }; default: console.error('Unsupported method: ', method); return null; } }
/** * 创建对象 */ create(req, res) { const rules = { name: joi.string().min(3).required(), comment: joi.string().min(2).required(), permissions: joi.array().default([]), }; const { error, value } = joi.validate(req.body, rules); if (error) { return res.replyError(error); } const AdminPermission = this.models['AdminPermission']; const permissions = value.permissions; permissions.push(this.defaultPermission); const result = AdminPermission.findAll({ where: { name: permissions } }).then((permissions) => { delete value.permissions; return this.sequelize.transaction((t) => { return this.model.create(value, { transaction: t }).then((role) => { return role.setPermissions(permissions, { transaction: t }).then(() => { }); }); }); }); res.reply(result); }
teamMembers: Joi.array().items(Joi.lazy(() => schema).description('Cyborg')) });
const array = Joi.array().single() const string = Joi.string() const comment = array.items(string) return Joi.object().keys({ comment: comment, value: (arrayAllowed ? array.items(singleValue) : singleValue).required() }) schema = schema.try(array.items( Joi.alternatives().try(singleValue).try(commentSchema(false)) )) contact: fieldValue({ required: true }), encryption: fieldValue({ singleValue: string.regex(/^(?!http:)/i) }), preferredLanguages: fieldValue({ canBeArray: false, singleValue: array.items(string) }), policy: fieldValue(), hiring: fieldValue(),