[英]How to resolve 2 different methods in one function on Apollo GraphQL resolver?
我有這個解析器
SLAccount: (_, { imsUserId, imsToken }, context) =>
new Promise((resolve, reject) => {
addAuth(context, imsUserId, imsToken);
context.model
.getUserAccount(getEndpoint(imsUserId, imsToken))
.then(resolve)
.catch(reject);
}),
但是我需要在其中包含另一個方法/模型:
getHardware(endpoint) {
return this.connector
.get(
`${endpoint}/...`,
)
.catch(res => this.handleError(res));
}
所以我需要這樣的東西:
SLAccount: (_, { imsUserId, imsToken }, context) =>
new Promise((resolve, reject) => {
addAuth(context, imsUserId, imsToken);
context.model
.getUserAccount(getEndpoint(imsUserId, imsToken))
.then(resolve)
.catch(reject);
context.model
.getHardware(getEndpoint(imsUserId, imsToken))
.then(resolve)
.catch(reject);
}),
問題是,我不需要同時調用它們,有時我只需要SLAccount
內部的那些方法/模型SLAccount
。
那么解決這個問題的最佳方法是什么?
GraphQL由需求(查詢)驅動。
當您需要account
只需進行查詢即可。 當您需要account
和相關hardware
只需查詢兩者-其他的解析器將被自動調用。 這是graphQL背后的基本思想。 查找有關graphQL中的關系的任何教程。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.