typescript - 如何在graphql和sequelize中过滤三向多对多关系?
问题描述
我已经为后端设置了一个带有 express 和 sequelize-typescript 的 GraphQL Apollo 服务器。我在以下表/模型之间具有三向多对多关系:
Action{
id: Int
name: String
participants:[Participant]
participanttypes: [ParticipantType]
}
Participant{
id: Int
displayname: String
actions: [Action]
participanttypes: [ParticipantType]
}
ParticipantType{
id: Int
description: String
actions: [Action]
participants: [Participant]
}
使用第四个模型将所有三个连接在一起
ActionParticipants{
id: Int
action: Int
participant: Int
participanttype: Int
}
我无法使用 GraphQL 过滤上述数据结构。例如,我想获取一个 Action,然后是该 Action 的 Participants,然后是该 Action 上每个参与者的 ParticipantType 描述。例如,使用返回第一个动作的 getAction(id:1) 查询
getAction(id:1){
name
participants{
displayName
participanttypes{
description
}
}
}
通过上面的查询,我将收到动作的名称,然后是该动作的参与者[名称]数组,最后是每个参与者的所有参与者类型描述。
但是,我想将参与者类型过滤为仅该操作的参与者。
解决方案
推荐阅读
- java - 要添加 each(3) 数组中的元素,如果总和不相等,则从数组中删除总和最高的最后一个元素
- html - 移动设备中的p列数据字段对齐
- ruby-on-rails - 删除保留上次使用 ActiveRecord 的重复记录
- python - 在点的确切位置显示 Bokeh 日期时间轴的标签
- python-3.x - 从数据框中计数,然后根据该计数进行排序
- scala - 无法绑定[SttpBackend[Try, Nothing]]
- git - 当本地分支已经存在时如何在 bitbucket 上创建拉取请求
- python - 如何在python中创建一个可以保存在内存中的CSV文件?
- android - Android 上的 Cognito UserPool 登录超时
- visual-studio - 如何访问从另一个应用程序调用的 Web 服务中的 web.config 部分?