apollo-client - Apollo-Client 字段策略:对带参数的字段使用 readField 句柄
问题描述
在 Apollo-Client 的缓存中定义字段read
策略时,有人知道是否可以使用readField
句柄来读取带参数的字段值?
例如,我的缓存中有以下对象:
parent {
id
child({"arg1"="A"})
child({"arg1"="B"})
}
当第二个参数(例如,)传递给该字段时,我需要在child
字段上设置读取策略以处理这些情况。换句话说,我需要根据(存在于缓存中)的值来读取(不存在于缓存中)。例如:parent
arg2
child({"arg1"="A","arg2"=true})
child({"arg1"="A"})
read(cached, { readField, args }){
if(!args?.arg2) return cached;
const cachedWithoutArg2 = ???
return doSomething(cachedWithoutArg2);
}
有什么办法吗?
解决方案
推荐阅读
- node.js - 如何在 Mongoose/MongoDB 中执行 $or 查询?
- mysql - 在 Objection.js 中按类型获取帖子?
- excel - 在 Excel 中爆炸(和内爆)骰子
- javascript - Turn array into objects in javascript
- android - Android 10 - 我想在外部存储上获取所有音频文件
- pytorch - 迭代地附加一维张量以生成二维张量
- html - 最大高度过渡仅在一个方向上起作用
- nestjs - 如何在 ServeStaticModule 中定义路径前缀?
- c# - 为什么这个 ListView 不与 ObservableCollection 元素绑定?
- ruby-on-rails - 如何迭代rails activeadmin CSV中的数组?