【发布时间】: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