[英]How to create service for angular2 + apollo-client with graphql
[英]How to fix: Angular Apollo-Client returning an array instead of an id
我在 angular 应用程序中使用的 apollo 客户端有问题。 我正在调用一个 graphQL-Query,它返回以下信息:
account: {id: 1}
accountId: 1
contact: {id: 1}
contactId: 1
id: 23
notes: null
resultId: null
stepId: 1
subject: "testsubject"
我在浏览器开发人员工具中看到了这个结果(调用的结果预览)到目前为止一切顺利,但是 appolo-client 返回了这个:
account: {id: 1}
accountId: 1
contact: {id: 1}
contactId: 1
id: {id: {…}, notes: null, stepId: 1, subject: "testsubject", resultId: null, …}
notes: null
resultId: null
stepId: 1
subject: "testsubject"
我在网上搜索了这个问题,但似乎我是唯一一个遇到这个问题的人,尝试解决几乎类似问题的方法并没有解决任何问题。
禁用缓存并没有解决它
this.apollo.create({
link: from([this.logoutLink, this.authMiddleware, graphQLDataLink]),
cache: new InMemoryCache({
addTypename: false
}),
defaultOptions: {
query: {
fetchPolicy: 'no-cache'
}
}
}
我发现了问题。 我用一种方法调用了 2 个查询,并隐藏了结果。 下面是简单的方法:
callGQLQuery(query1).then(result => { ...一些代码 callGQLQuery(query2).then(result => { => 这里的结果有我描述的这个错误,改变 result2 中的第二个结果解决了它}) })
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.