Graphql 棱镜ORM查询关系用户
我正试图在棱镜ORM中查询1:1关系 但在查询时,它总是返回null 这是我的数据模型:Graphql 棱镜ORM查询关系用户,graphql,prisma,prisma-graphql,Graphql,Prisma,Prisma Graphql,我正试图在棱镜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
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
};
您返回的是一个author对象,而不是post对象。@DanielRearden但我希望post与附加到该post的author一起:)我怎么能这样做?您阅读了吗?@DanielRearden谢谢您将检查片段api:)@DanielRearden我想查询关系会是这样的: