【发布时间】:2020-08-08 06:22:15
【问题描述】:
我有一个如下所示的查询:
export const GET_PROJECT = gql`
query GetProject($id: String!) {
homework {
getProject(id: $id) {
...ProjectFields
}
}
}
${ProjectFieldsFragment}
`;
我的InMemoryCache 看起来像这样:
const cache = new InMemoryCache({
dataIdFromObject: ({ id }) => id,
cacheRedirects: {
Query: {
getProject: (_, args, obj) => {
console.log('Hello world');
},
},
}
});
上述缓存重定向永远不会命中。但是,如果我将其修改为:
const cache = new InMemoryCache({
dataIdFromObject: ({ id }) => id,
cacheRedirects: {
Query: {
homework: (_, args, obj) => {
console.log('Hello world');
},
},
}
});
它确实受到了打击,但是我没有任何在嵌套的 getProject 查询中传递的参数。同样令人困惑的是,这个缓存重定向功能会针对看起来不应该被命中的查询命中,例如:
export const SESSION = gql`
query Session {
session {
user {
id
fullName
email
}
organizations {
name
id
}
}
}
`;
那么发生了什么?我只在希望缓存重定向的地方使用了readFragment,但我希望该逻辑变得集中。
【问题讨论】:
标签: caching react-apollo