我有三個不同的PostGres表,每個表都包含不同類型的同事。數據庫字段對於每種類型都不相同 - 這就是爲什麼它們位於三個不同的表中。Apollo GraphQL:查詢返回不同類型對象的模式?
我有一個組件可以訪問任何類型的關聯。現在看來,從我到目前爲止所遇到的例子,一個組件通常與一個GraphQL查詢,如相關:
const withData = graphql(GETONEASSOCIATE_QUERY, {
options({ navID }) {
return {
variables: { _id: navID}
};
}
,
props({ data: { loading, getOneAssociate } }) {
return { loading, getOneAssociate };
},
});
export default compose(
withData,
withApollo
)(AssociatesList);
而它的出現給定GraphQL查詢,只能返回單個輸入記錄的,例如在架構:
getOneAssociate(associateType: String): [associateAccountingType]
問題:是可以設計一個GraphQL架構使得單個查詢,可以返回不同類型的對象?解析器可能會收到一個associateType參數,它會告訴它要引用哪個postGres表。但是模式是什麼樣子的,以便它可以根據需要返回類型爲associateAccountingType,associateArtDirectorType,associateAccountExecType等的對象?
在此先感謝所有的任何信息。