【发布时间】:2022-04-06 06:21:48
【问题描述】:
在 Apollo-Client 的缓存中定义字段 read 策略时,有人知道是否可以使用 readField 句柄来读取带参数的字段值?
例如,我的缓存中有以下对象:
parent {
id
child({"arg1"="A"})
child({"arg1"="B"})
}
我需要在parent 的child 字段上设置读取策略,以在将第二个参数(例如arg2)传递给该字段时处理这些情况。换句话说,我需要根据child({"arg1"="A"})(存在于缓存中)的值来读取child({"arg1"="A","arg2"=true})(不存在于缓存中)。例如:
read(cached, { readField, args }){
if(!args?.arg2) return cached;
const cachedWithoutArg2 = ???
return doSomething(cachedWithoutArg2);
}
有什么办法吗?
【问题讨论】:
标签: apollo-client