可以使用“ apollo-cache-hermes”代替apollo-cache-memory吗?

由于InmemoryCache的性能问题,我试图将我们的应用迁移到爱马仕缓存。因为在我将缓存更改为使用writeData之前,它是通过writeFragment完成缓存初始化的。

所以init函数看起来像:

const initCache = cache => {
  let fragmentString = gql`
    fragment test on MyType {
      ...myTypeFragment
    }
    ${fragments.myTypeFragment}
`;
let fragment = {
  id: "myType",fragment: fragmentString,fragmentName: "test"
  data: {
    __typename: "MyType",...
  }
};
cache.writeFragment(fragment);

使用的片段是片段集合的一部分,并具有以下结构:

const fragments = {
  myType: gql`
    fragment myTypeFragment on myType {
      __typename,...
  `,...
}

使用Apollo开发工具,我可以看到在缓存中创建了以下条目:

"ROOT_QUERY": {
  "data": {
    "myType": null
  }
}
"myType": {
  "data": {
    "__typename": "MyType",...
  }
}

myType条目看起来不错,但是ROOT_QUERY条目始终为null。他们之间似乎也没有任何参考。

预期行为

使用

const data = useQuery(GET_MY_TYPE,{ onCompleted: data => console.log(Data) });

使用

const GET_MY_TYPE = gql`
  query getMyType {
    myType @client {
      ...myTypeFragment
    }
  }
  ${fragments.myTypeFragment}
`;

我希望看到一条日志消息,其中包含来自缓存中myType条目的数据。在GraphiQL中执行此查询也应产生此结果

实际行为

相反,永远不会调用onCompleted。在GraphiQL中执行查询会返回

{
  "data": {
    "myType": null
  }
}

系统信息

  • 操作系统:
    • Linux 5.0 Ubuntu 19.04(Disco Dingo)
  • 二进制文件:
    • 节点:13.5.0-/ usr / local / bin / node
    • npm:6.13.4-/ usr / local / bin / npm
  • 浏览器:
    • Firefox:71.0
  • npmPackages:
    • @ apollo / react-hooks:3.1.3 => 3.1.3
    • apollo-cache-hermes:^ 0.8.10 => 0.8.10
    • 阿波罗缓存内存:^ 1.6.5 => 1.6.5
    • 阿波罗客户:^ 2.6.8 => 2.6.8
    • 阿波罗链接:^ 1.2.13 => 1.2.13
    • apollo-link-error:^ 1.1.12 => 1.1.12
    • apollo-link-http:^ 1.5.16 => 1.5.16
    • 反应阿波罗:3.1.3 => 3.1.3
ccdelan 回答:可以使用“ apollo-cache-hermes”代替apollo-cache-memory吗?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2885726.html

大家都在问