【发布时间】:2022-01-08 19:48:00
【问题描述】:
所以我的应用中有一个station。这是一个示例对象:
interface Station {
id: number; // auto-increment
stationId: number; // this is a constant
name: string;
status: 'live' | 'draft';
}
更新station 时,stationId 永远不会改变,但 sql 会自动增加 id 字段。电台的status也将更新为'draft'。例如
const previousStation: Station = {
id: 1,
stationId: 123456,
name: 'Example splet right',
status: 'live',
}
// ... then some sql-fu
const nextStation: Station = {
id: 2,
stationId: 123456,
name: 'Example spelt right',
status: 'draft',
}
Apollo 客户端无法推断nextStation 应该替换previousStation,因此有很多突变需要readQuery/readFragment。
我希望可能有一个更简单的解决方案,但复杂性来自id 的更改。如果我可以在规范化数据缓存中找到对其对象 ID 的所有引用并更新这些字段。这样的事情有可能吗?
【问题讨论】:
标签: apollo-client react-apollo