我有简单的A型数据模型。类型A有一个nameCode,它是数组。而且我需要将数据传递给数组。
datamodel.prisma
type A {
id: ID! @id
code: String
nameCode: [String]
product: Product!
user: User!
}
当我将数据传递给“代码”时,它工作正常。但是,当我传递给“ nameCode”时,出现了错误。
我需要将getCode传递给“ nameCode”
Mutation.js
async test(parent, args, ctx, info) {
const user = await ctx.db.query.user({where:{id: ctx.request.userId}})
const product = await ctx.db.query.product({where:{code: args.create.product.connect.code}})
args.create.code = await getCode(ctx, user, product)
}
getCode
const getCode = (ctx, user, product) =>{
return new Promise( async (resolve, reject)=>{
const code = await ctx.db.query.code({
where:{
user:{
id: user.id
},
product:{
id: product.id
}
}
})
resolve(product.code +'-'+ (code.length +1))
})
}
exports.getCode = getCode
您不能这样声明nameCode: [String]
,只需将其设置为
nameCode:{}
到此为止,您将获得想要的确切东西。