我试图找出GraphQL中的级联删除。
我正在尝试删除类型为的节点Question,但是类型QuestionVote与的关系是必需的Question。我正在寻找一种同时删除Question和及其所有投票的方法。
用于删除的突变Question:
type Mutation {
deleteQuestion(where: QuestionWhereUniqueInput!): Question!
}
Run Code Online (Sandbox Code Playgroud)
及其解析器(我正在使用Prisma):
function deleteQuestion(parent, args, context, info) {
const userId = getUserId(context)
return context.db.mutation.deleteQuestion(
{
where: {id: args.id}
},
info,
)
}
Run Code Online (Sandbox Code Playgroud)
如何修改该突变以删除相关QuestionVote节点?还是应该添加一个单独的突变来删除一个或多个实例QuestionVote?
如果很重要,这里是创建Question和的突变QuestionVote:
function createQuestion(parent, args, context, info) {
const userId = getUserId(context)
return context.db.mutation.createQuestion(
{
data: {
content: args.content,
postedBy: { connect: { id: userId } },
},
},
info,
) …Run Code Online (Sandbox Code Playgroud)