GraphQL angular 阿波罗客户端。从缓存中读取抛出错误,但对服务器的相同查询工作正常

GraphQL angular apollo-client. Read from cache throw error but the same query to the server works fine

我正在尝试从已经存在的缓存中请求数据。我检查了 Apollo Chrome 插件的用法。

      const inCache = this.apollo.getClient().readQuery({
        query: gql`
          query {
            foo(id: "foo0") {
              id
              bar {
                id
              }
            }
          }
        `
      });

错误如下所示:

MyHtml.html:20 ERROR Invariant Violation: Can't find field id on object {
  "barSubResourses": [
    {
      "type": "id",
      "generated": false,
      "id": "SubResourse:subResourse3",
      "typename": "SubResourse"
    },
    {
      "type": "id",
      "generated": false,
      "id": "SubResourse:subResourse2",
      "typename": "SubResourse"
    }
  ],
  "__typename": "Bar"
}.

如果我不包含子资源,从缓存读取工作正常 有人知道吗?

终于找到问题的根源了。在我的查询中有一个没有 id for Bar 的查询。我已经仔细检查了 chrome 插件是否仍然具有条形图的 ID 数据。看起来不匹配。 无论如何,似乎有一条经验法则要求每个查询中的每个实体 id