代码之家  ›  专栏  ›  技术社区  ›  Cisum Inas

在缓存重定向中找不到缓存密钥

  •  0
  • Cisum Inas  · 技术社区  · 5 年前

    当我启动我的React原生应用程序时,我不想查询“一切”来获得离线体验。

    所以我

    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

    1 回复  |  直到 5 年前
        1
  •  0
  •   Cisum Inas    5 年前

    这是由于我们使用了 身份证件 在人的领域,因为我们停止使用领域,它工作完美。