如何与阿波罗建立多对多关系?

时间:2019-04-14 15:18:39

标签: reactjs typescript graphql apollo react-apollo

所以我为此付出了很多努力,我不确定为什么。

想法是为用户添加通知,从而实现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}
  }
}

enter image description here

{
  "data": {
    "User": {
      "username": "baldrani",
      "notifications": null
    }
  }
}

0 个答案:

没有答案