Joi.array().items(Joi.object().keys({ name: Joi.string().required(), value: Joi.required() }).unknown(true)).unique((a, b) => a.name === b.name)
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) ); });
function models() { const product = Joi.object().keys({ name: Joi.required(), price: Joi.required(), weight: Joi.required() }); const order = Joi.object().keys({ product_list: Joi.array() .items(Joi.number()) .required() }); return { product, order }; }
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; } }
Joi.array().items(Joi.object().keys({ name: Joi.string().required(), value: Joi.required() })).unique((a, b) => a.name === b.name)
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(),
Joi.array().items(Joi.object().keys({ name: Joi.string().required(), value: Joi.required() }).unknown(true)).unique((a, b) => a.name === b.name)