Caching field exception

Question about caching.
Is it possible to cache the result of a query but not a specific field?

For example, I have a listing and a specific field contains a dynamic value that has to change, is it possible to cache all the other fields but not that specific one?

So that even if I load from the cache, the specific field is always queried?

I don’t think so but I wanted to ask.

Thanks.

You can have two queries: one that fetches all fields including the object ID, and one that fetches only the dynamic field and the object ID.

The query that only gets the dynamic field should be configured to never use the cache. You can have this query every time a certain page or component loads. The other query will check for cached values first, which is the default behavior.

Because the Apollo cache will use the ID to reconcile values, it will update only the dynamic value in the cached object data.

2 Likes

Yeah I figured that could be one of the only ways.
I am wondering if its possible to have the query that fetches for the dynamic field act like sort of a dataloader.

If I have a query with X items and each of their dynamic field requires me to query my server for that information, i’d like it to be batched all together into one query instead of doing it per item.

Also, I assume maybe I could use the caching methods to execute this query instead of having to separate useQuery in a component?

Maybe using something like this: Customizing the behavior of cached fields - Apollo GraphQL Docs

The only issue I see here in that, is that I don’t seem to have access to the object so that I can get its _id in order to query for any additional data.

Or maybe this: Local-only fields in Apollo Client - Apollo GraphQL Docs

Anyway thanks for your input, I am just thinking aloud.