如何从阿波罗缓存中删除嵌套对象?
How to remove nested object form apollo cache?
Official doc 说使用 cache.evict()
删除缓存数据,但没有关于嵌套对象的解释。例如,让我们考虑如下 ROOT_QUERY
。
ROOT_QUERY: {
analysis: {
receipts: {
...
}
}
}
我可以使用 cache.evict()
删除 analysis
字段。
cache.evict({ id: 'ROOT_QUERY', fieldName: 'analysis' });
但是,如何删除 receipts
字段?
您可以对嵌套对象使用 cache.modify
。
cache.modify({
id: 'ROOT_QUERY',
fields: {
analysis(existing) {
return {
...existing,
receipts: undefined
};
}
}
});
Official doc 说使用 cache.evict()
删除缓存数据,但没有关于嵌套对象的解释。例如,让我们考虑如下 ROOT_QUERY
。
ROOT_QUERY: {
analysis: {
receipts: {
...
}
}
}
我可以使用 cache.evict()
删除 analysis
字段。
cache.evict({ id: 'ROOT_QUERY', fieldName: 'analysis' });
但是,如何删除 receipts
字段?
您可以对嵌套对象使用 cache.modify
。
cache.modify({
id: 'ROOT_QUERY',
fields: {
analysis(existing) {
return {
...existing,
receipts: undefined
};
}
}
});