node.js - 如何为给定的 graphql 联合类型查询两个 mongoose 集合?
问题描述
我有两个系列:companies
和people
. 我也有这个 graphql 架构
type Company {
id: ID!
...
}
type Person {
id: ID!
...
}
union Customer = Company | Person
type Query {
allCustomers: [Customer!]
}
现在我的解析器看起来像这样:
allCustomers: async () => {
const [customers, people] = await Promise.all([
Company.find(),
Person.find(),
])
return [...customers, ...people]
}
有没有更好的方法来查询数据库?或者这样可以吗?
解决方案
推荐阅读
- postgresql - PostgreSQL:第一次日期累积分数
- google-apps-script - 从 Google 电子表格访问 Google 脚本中的存储值
- google-nearby - 附近发送的文件打不开
- javascript - 动态创建div时只允许一个根元素出错
- python - eval()的奇怪行为与python循环中的lambda函数
- html - 如何保存浏览器渲染的缩放图像
- git - 在本地存储库是更新的存储库时恢复 .git 文件
- python - 没有输出的重启错误
- html - css 动态叠加
鼠标悬停不透明度 - java - 使用不同的 java jdk 版本在 IntelliJ 中导入 Gradle 项目