在Cache重定向中找不到缓存键

问题描述 投票:0回答:1

当我启动我的本机应用程序时,我不想查询“一切”以获得离线体验。

所以我

query all {
  groups {
    ...GroupF
  }

  persons {
    ...PersonF
  } 
}${PERSON_ITEM}${GROUP_ITEM}

人和群是碎片。

第一个视图有一个组列表,每个人都可以属于一个组。当用户单击某个组时,查询如下所示:

persons($group: ID) {
  persons(group: $group) {
    ...PersonsF
  }
}${PERSON_ITEM}

但我的cacheRedirects并不反映与返回的数据相同的数据。

我知道这个,因为我在我的组件包装器中调用了我的响应(在这里看起来很棒)

但在我的

const cache = new InMemoryCache({
  cacheRedirects: {
    Query: {
      persons: (_, args, {getCacheKeys}) => {
       // I have tried everything here but nothing maps correctly
       // I have tried getCacheKey({__typename: 'Person', id: args.group})
       // I have tried following the apollo documentation
       // No luck, it just can't find the group
       // Using the chrome dev tools I don't see persons having groups
       const a = getCacheKey({__typename: 'Person', id: args.group});
       // Console.log(a) is:
       // {generated: false, id: "Person:9", type: "id", typename "Person"}
      }
    } 
  }
});

您对如何编写适当的缓存重定向人员查询有什么建议吗?

帮助真的非常感激

| 1 | https://www.apollographql.com/docs/react/advanced/caching.html#cacheRedirect

graphql react-apollo apollo-client aws-appsync
1个回答
0
投票

这是因为我们在Person中使用了id字段,因为我们使用它完全正常工作的字段停止了。

© www.soinside.com 2019 - 2024. All rights reserved.