棱镜ORM查询关系用户



我正在尝试在Prisma ORM中查询1:1关系 但是在查询时它总是返回 null

这是我的数据模型:

enum Role {
ADMIN
MEMBER
CONSTRIBUTOR
}
type User {
id: ID! @id
name: String! @unique
email: String! @unique
password: String!
posts: [Post!]!
role: Role @default(value: MEMBER)
}
type Post {
id: ID! @id
title: String
excerpt: String
content: Json
author: User! @relation(link: INLINE)
}

我试图查询带有用户的作者的帖子:

但是在我的解析器中,当我这样做时:

getPost: async (parent, args, ctx, info) => {
if (args.id) {
console.log('GET POST by ID');
const id = args.id;
return await ctx.prisma.post({ id }).author();
}
},

它始终返回 Null。有人知道如何解决它吗?

通过使用对作者的 sperate 查询来修复它,如下所示:

const author = await ctx.prisma.post({ id: id }).author();
const post = await ctx.prisma.post({ id });
return {
...post,
author
};

最新更新