How to prevent apollo from updating cache with child objects in query?
See original GitHub issueI apologize in advance for posting this question here but I really don’t want to sign up for another website IE spectrum for asking a singular question.
I have a query for a Reading object that goes something like this
readings(queryObject: $queryObject) {
items {
id
meeting {
id
startDateTime
endDateTime
}
nomination {
id
book {
name
author
imageUrl
}
pitchedByFullName
date
}
...
}
hasMore
}
It’s a big object with lots of children. In a different part of my application I make a query for a Meeting object. As part of this query I need two pieces of specific information about the Reading object
meetings(queryObject: $queryObject) {
items {
id
...
amIGoing
reservationId
readings {
id
nomination {
book {
imageUrl
}
}
}
}
When I do this query apollo is going to clear out the cache for the Reading object with that id and replace it with this partial fetch. How do I prevent this from happening? One of the great things about GraphQL is that I can tailor queries to get just the information that I need but your caching sends the message that if i get the id of the object I better get every field I could possibly want because that’s what will end up in the cache.
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (2 by maintainers)
Top GitHub Comments
Is it possible to make Apollo smarter? If I query 3 out of 10 fields on an object and then later on query 10 out of 10, can Apollo understands that the second query requires more fields and not replace the object but update the object with a new query?
I would say that updating the cache automatically with child objects, based on the
__typename
andid
, do more good than harm. Often times you will have mutations that have impacts on multiple queries, and it’s super hard to manually update all the queries affected by a single mutation.In your case, if you don’t want it to update the cache automatically, maybe don’t include the
id
in your child document schema?