在prisma 1中,我使用片段来获取嵌套字段。
例如:
const mutations = {
async createPost(_, args, ctx) {
const user = await loginChecker(ctx);
const post = await prisma.post
.create({
data: {
author: {
connect: {
id: user.id,
},
},
title: args.title,
body: args.body,
published: args.published,
},
})
.$fragment(fragment);
return post;
},
};但在prisma2中,它似乎不受支持。因为通过在操场上运行这个,
mutation CREATEPOST {
createPost(
title: "How to sleep?"
body: "Eat, sleep, repaet"
published: true
) {
title
body
published
author {
id
}
}
}我得到了,
"prisma.post.create(...).$fragment is not a function",发布于 2020-05-27 22:14:16
包括选项用于在Prisma中急切地加载关系。
文档中的示例:
const result = await prisma.user.findOne({
where: { id: 1 },
include: { posts: true },
})假设用户表具有一对多的posts关系,这也将返回带有posts字段的user对象。
Prisma也支持嵌套,例如:
const result = await prisma.user.findOne({
where: { id: 1 },
include: {
posts: {
include: {
author: true,
}
},
},
})https://stackoverflow.com/questions/62046070
复制相似问题