我们应该如何在 Apollo GraphQL 中设置 ManyToMany 关系

How are we suppose to set a ManyToMany relationship in Apollo GraphQL

我想在 NotificationUser(收件人)之间建立多对多关系。

所以根据我你必须创建一个类似于 NotificationRecipients 的中间类型。

但是我该做什么样的关系呢?

是不是有点像

Notification OneToMany <---> ManyToOne NotificationRecipients ManyToOne <---> OneToMany User

这在 apollo 的文档中没有任何解释。这听起来不太好,因为它应该是 ManyToMany 关系无处不在...

是否有 @ManyToMany 指令?

"Relation" 在 GraphQL 中并不是第一个 class 术语。如果 Notification 有很多用户,你就这么说,反之亦然

type Notification {
  users: [User!]!
}
type User {
  notifications: [Notification!]!
}

作为链接问题注释的答案,如果适合您,您可以在此处使用中继连接模式。

实际实现取决于您(在您的解析器函数中)或您正在使用的数据库粘合层。 GraphQL 只是在这里定义了一个 API,它并没有严格地绑定到你的数据库布局。