Как получить отношение Многих ко Многим с Аполлоном? - PullRequest
0 голосов
/ 14 апреля 2019

Так что я изо всех сил стараюсь из-за этого, и я не уверен, почему.

Идея состоит в том, чтобы добавить уведомления для пользователей, чтобы иметь отношение к 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
    }
  }
}
...