【问题标题】:Can't find cache key in Cache redirect在缓存重定向中找不到缓存键
【发布时间】:2019-05-13 15:33:28
【问题描述】:

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

所以我

query all {
  groups {
    ...GroupF
  }

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

PersonF 和 GroupF 是片段。

第一个视图有一个组列表,每个人都可以属于一个组。当用户点击一个组时,查询看起来像:

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

但我的 cacheRedirects 只是没有反映返回的相同数据。

我知道这一点,因为我在我的组件包装器中 console.log out 响应(这里看起来很棒)

但在我的

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】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-31
      • 2018-04-09
      • 1970-01-01
      • 2015-02-26
      • 2011-10-22
      • 2017-05-30
      • 2012-02-19
      相关资源
      最近更新 更多