【发布时间】:2020-09-23 11:19:34
【问题描述】:
我第一次使用 GraphQl 和 Prisma,我试图在我的解析器突变文件中创建一个更新功能,但我一直在努力解决它。我做了一些研究,但我发现的东西不适用于我的代码。我总是以错误告终。有人可以帮我解决这个问题吗?
架构:
type Service {
id: ID!
createdAt: DateTime!
updatedAt: DateTime!
name: String!
cost: Float!
description:String
hours: Int!
minutes: Int!
postedBy: User!
}
type Mutation {
postService(name: String!, cost:Float!,description:String!,hours: Int!, minutes: Int! ): Service!
deleteService(id: ID!): Service!
updateService(name: String!, cost:Float!,description:String!,hours: Int!, minutes: Int!): Service!
}
变异解析器:
function updateService(parent, args, context, info) {
return context.prisma.mutation.updateService({
cost: args.cost,
name: args.name,
description: args.description,
hours: args.hours,
minutes: args.minutes,
postedBy: { connect: { id: userId } },
where: {
id: args.where.id
}
}, info)
}
在 prisma 游乐场中查询:
mutation{
updateService(
name: "Update test"
where:{
id : "ckaz82x01aqq50a42fkrz3uxu"
}
){id
name
hours
minutes}}
【问题讨论】:
标签: sql-update prisma mutation prisma-graphql