我有两个集合: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]
}
是否有更好的方法来查询数据库?还是可以吗?