所以我为此付出了很多努力,我不确定为什么。
想法是为用户添加通知,从而实现ManyToMany关系。这是我在做什么
//entity/Notifications
@ManyToMany(type => User, recipient => recipient.notifications)
@JoinTable()
recipients: User[];
//entity/User
@ManyToMany(type => Notification, notification => notification.recipients)
notifications: Notification[];
//resolver
Query: {
...
Notification: (_, { id }, __) => {
return Notification.findOne(id, { relations: ["recipient"] });
},
allNotifications: (_, __, ___) => {
return Notification.find({ relations: ["recipient"] })
}
}
//typeDefs
type Notification {
id: ID
template: String!
seen: Boolean!
recipients: [User]
}
type User {
id: ID!
notifications: [Notification]
}
我不知道是否放弃了某些东西,但是我无法弄清楚它是什么,现在我只能从查询中得到empyt输出:
{
User(id: "ca5a71b0-c47e-412a-8cca-602f22c76471"){
username
notifications
{id}
}
}
{
"data": {
"User": {
"username": "baldrani",
"notifications": null
}
}
}