-
Notifications
You must be signed in to change notification settings - Fork 787
Caching fragments / single fields #792
Comments
We intentionally don't modify the queries in any way before sending them to the server. If you put This is because it would be easy to end up with inconsistencies between the fields if they were fetched at a different time. If you want the behavior above, I'd suggest using multiple queries. |
@stubailo Haven't Apollo's team consider such caching strategy as an option? It opens the door to more declarative query<->component connections, where more granular queries are assigned to smaller components and prefetching is easier due to the data updates being handled behind the stage, in Apollo internals. This would also mean better encapsulation end reusability of components. EDITL: Or event better - the above mentioned per-graphbranch caching (in comparison with per-query caching like now is implemented in Apollo, as I understand) could be the default mode and opting out from this mode (= fetching the whole query independently of what is already in store) could be done based on some additional option to the Do you think that could work, is it event possible? The idea is something that my team would like to work with, a result of mind-storming and experience with hooking up Apollo into a big project. |
This issue has been automatically marked as stale becuase it has not had recent activity. It will be closed if not further activity occurs. Thank you for your contributions to React Apollo! |
This issue has been automatically labled because it has not had recent activity. If you have not received a response from anyone, please mention the repository maintainer (most likely @jbaxleyiii). It will be closed if no further activity occurs. Thank you for your contributions to React Apollo! |
@stubailo @helfer @calebmer @jbaxleyiii @Poincare It is clearly stated in this article (y. 2016): https://dev-blog.apollodata.com/the-concepts-of-graphql-bc68bd819be3 that Apollo implements per-field caching. It says, that if I send two completely different queries having the same item in them, the item in the second query will be omitted:
So what has changed since 2016 that Apollo doesn't do that any more? Or maybe there is some way to enable it after all? |
We intentionally removed this feature in 0.5: https://github.com/apollographql/apollo-client/blob/master/CHANGELOG.md#v050-0-first-preview
For more info check this article which explains some of the reasoning: https://dev-blog.apollodata.com/5-benefits-of-static-graphql-queries-b7fa90b0b69a |
Disclaimer: not sure if doing something wrong and can't get it working or just not implemented.
To the point:
I'd like to achieve caching on more granular level than just queries - caching fragments or even fields.
I'll use a simple example to introduce the problem:
Let's say we have the following query, defining data requirements for component
Abc
:When I mount
Abc
, the request withBigQuery
is sent and after a while I receive a response with data. ButAbc
is a big component (whole view perhaps) andBigQuery
takes long time to return all the necessary data. And so I want to preload some of it, to render the critical path of the component. So I fire the following query beforehand:Now after
PreloadedData
is processed, I seeb
andc
in the redux store of Apollo. When it comes to fireBigQuery
afterwards, I notice in devtools that Apollo asks not only for the remaining:a
andd
, but also forb
andc
, even though it's already in store.I tried to use fragment like this, but it changed nothing:
Maybe
customResolvers
are the way to go, to hint Apollo how to resolve types?If I haven't mixed something up or missed a part from docs, my suggested solution would be to check the store in search for already downloaded fields and exclude them from the query and/or cache fragments in the same way as whole queries.
The text was updated successfully, but these errors were encountered: