Apollo 在 React 中混合来自 GraphQL 查询的结果

Apollo is mixing results from a GraphQL Query in React

我正在打电话 returns 问题和他们的答案。当我直接对服务器进行此操作时,响应符合预期。此外,当 React 发出调用并且我检查开发人员工具时,响应符合预期。

一旦我收到 Apollo 的回复,数据就会变得混乱,结果会相互渗透。

你会注意到这两张图片,展开一些结果后的结果是一样的。我不确定是什么原因造成的。

为什么 freeform 会合并?

我的设置是这样的:

我导入查询,然后 运行 在 Apollo 客户端上执行此操作:

this.props.client.query({ query: getCoreObjectsQuery, variables: { companyId: 1}})
              .then((result) => {
                console.log(result, 'getCoreObjectsQuery')

从那里,当我去查看 getCoreObjectsQuery 时,它看起来像上面的图像!

哇!原来是 Apollo Client 缓存错误。

Kamranicus.com 有一篇关于此的非常有用的文章,但对于任何寻求快速修复的人:

__typename @skip(if: true)

questions{
      id
      __typename @skip(if: true)
      coreId
      question
      isCore
      type
      answer:answerForCoreId{
         id
         __typename @skip(if: true)
         freeform
         url
         choice {
           id
           __typename @skip(if: true)
         }
       }
    }

id和_id缓存!