【问题标题】:How to fix: Angular Apollo-Client returning an array instead of an id如何修复:Angular Apollo-Client 返回一个数组而不是一个 id
【发布时间】:2020-01-14 00:38:38
【问题描述】:

我在 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'
          }
        }
      }

【问题讨论】:

    标签: angular apollo-client


    【解决方案1】:

    我发现了问题。我在一种方法中调用了 2 个查询,并隐藏了结果。这是简单的方法:

    callGQLQuery(query1).then(result => { ...一些代码 callGQLQuery(query2).then(result => { => 这里的结果有我描述的这个错误,将第二个结果更改为 result2 解决了 }) })

    【讨论】:

      猜你喜欢
      • 2020-11-02
      • 2016-05-03
      • 2015-05-10
      • 2016-06-27
      • 1970-01-01
      • 2016-06-21
      • 2022-12-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多