Hello hello ! Im a bit confused regarding CacheKey...
# apollo-kotlin
m
Hello hello ! Im a bit confused regarding CacheKeys and removals. given this declarative key
extend type  WorkOrderType  @typePolicy(keyFields: "id")
and this records key like:
Copy code
workOrder({"id":"J-2B387F98"})
workOrder({"id":"J-2B387F98"}).project
The proper way to delete them would be
Copy code
apolloClient.apolloStore.remove(CacheKey("WorkOrder:${workorderId}"))
but it has no effect
m
There are object keys and field keys.
workOrder({"id":"J-2B387F98"})
sounds like a field key from the root for a query like
Copy code
query GetWorkOrder($id: String) {
  workOrder(id: $id) { ... }
}
This field key should point to the object key like
CacheKey("WorkOrder:${workorderId}")
But removing the
CacheKey("WorkOrder:${workorderId}")
record doesn’t remove the root field references (if this is what you were expecting?)
m
Hmm interesting, what woulb be the correct way to delete that root reference? ( and cascade?
m
No real good solution so far
m
does that mean that my declarative keys are wornlgy set?
m
If you wanted to remove a field in the root record, you’d have to overwrite the root record currently
m
write the cache then? setting it blank on purpose?
m
yep
That would trigger the watchers if this is what you’re after
The easiest way is to call
writeOperation
with the new data
m
Im not watching the cace but Id liek to evict the resutl for that query so if they re enter they neednetwork agan
ok
thanks!
m
Sure thing!
Note that removing
CacheKey("WorkOrder:${workorderId}")
should still trigger a cache miss
The cache will read
workOrder({"id":"J-2B387F98"})
which points to
CacheKey("WorkOrder:${workorderId}")
and trigger a cache miss at that point
If not, it means there’s something else. If you’re not already using it, the IJ plugin cache viewer can help there
m
excelllent
thnaks again
m
No problem! Let us know how that goes!
m
sure thing