When defining a field read policy in Apollo-Client's cache, does anybody know if it's possible to use readField handle to read values of fields with arguments?
E.g., I have the following object in my cache:
parent {
id
child({"arg1"="A"})
child({"arg1"="B"})
}
I need to set a read policy on a child field of parent to handle those cases when a second argument (e.g., arg2) is passed to that field. In other words, I need to read child({"arg1"="A","arg2"=true}) (not present in cache) based off of the value of child({"arg1"="A"}) (present in cache). E.g.:
read(cached, { readField, args }){
if(!args?.arg2) return cached;
const cachedWithoutArg2 = ???
return doSomething(cachedWithoutArg2);
}
Is there any way to do it?
A bit late to the party, but you can use the extended version of readField to pass arguments to that specific read -> readField({ fieldName: 'child', args: { arg1 })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With