[英]prisma2: how to fetch nested fields?
In prisma 1 I have used fragment to fetch the nested fields.在 prisma 1 中,我使用片段来获取嵌套字段。
For example:例如:
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;
},
};
but seems like in prisma2 it is not supported.但似乎在 prisma2 中不受支持。 because by running this on playground,
因为通过在操场上运行它,
mutation CREATEPOST {
createPost(
title: "How to sleep?"
body: "Eat, sleep, repaet"
published: true
) {
title
body
published
author {
id
}
}
}
I am getting,我正进入(状态,
"prisma.post.create(...).$fragment is not a function",
The include option is used to eagerly load relations in Prisma 2. include 选项用于在 Prisma 2 中急切地加载关系。
Example from docs:来自文档的示例:
const result = await prisma.user.findOne({
where: { id: 1 },
include: { posts: true },
})
Assuming a user table with a one to many posts relation, this will return back the user object with the posts field as well.假设用户表具有一对多的帖子关系,这将返回用户 object 以及帖子字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.