-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: updateQuery method that can operate on all variables a query has been cached with #230
Comments
One problem with this structure is just that the cache doesn't store variables for queries. It could support iteration like this but it'd have to pass you the unique |
@danReynolds I mean it sort of does already, because the variables are serialized in the cache keys. But yeah ideally they should be stored unserialized somewhere, as well as efficient data structures that can point us to all the variable bindings and corresponding data for a given query or field. Choice of implementation details (like store field names) should support the goals of an ideal API design, not the other way around. Even if something is not possible with the current implementation, let's keep open minds about what can be made possible. I'm sure the Apollo team will make these improvements to the cache sooner or later because it's going to be the only way to manage cache updates in a large app in a sane way unless you force the responsibility for storing variables into userland. Right now refetching is virtually the only option in a lot of cases. For example, if you want to insert a newly created item in the correct sorted position in all applicable lists in the cache, you probably need to know variables that determine the sort order and list range for each of those queries. |
Yea you can't just parse the store field name though because field directives for example are also added to it. I'd vastly prefer for them to store variables separately as a first class entity of fields that we can access. I assume the concern with that is mostly bloating the cache size. |
It's hard to imagine a case where the variables take up even close to as much space as the data though |
This comment has been minimized.
This comment has been minimized.
Imagine having a search field in your query: variables size can easily get huge. |
@darkbasic you're saying if the search is really long? Or that each keystroke would create another set of variables? (I'm assuming they wouldn't remain cached forever unless data gets loaded, which would probably be larger than the search term) |
Not each keystroke because you definitely want to debounce this, but you will end up with plenty of search terms anyway. Lots of them could have little to no results. |
Only one will be active though so others would get garbage collected if the cache gets too big right? |
Also since the variables already get stringified into the cache keys, any size problems are already present. Storing the unstringified variables wouldn't be a very substantial increase relative to that. |
@benjamn although you're restoring |
Thanks for the great discussion here @jedwards1211. We'd like to keep issues here for bugs only, so I'm going to transfer this issue over to our FR repo. Thanks again! |
I think I probably failed to notice the link in the feature request template, my apologies! |
@benjamn
With the removal of
cache.modify
, there's still no simple way to remove a deleted item from all cached queries, since they could be called with many different variables. (apollographql/apollo-client#6289 (comment), apollographql/apollo-client#6289 (comment)).To solve this without the problems
cache.modify
had, I propose anupdateQuery
method, as illustrated below. This would be so similar to the existingreadQuery
/writeQuery
methods that it wouldn't risk confusing user in the way thatcache.modify
did, and it would be very easy to document. But unlikereadQuery
andwriteQuery
, it would allow us to update query results for all cached variables in one fell swoop by omitting thevariables
option.It would also be more convenient for most existing cases where
readQuery
followed bywriteQuery
is used (I've been using a userlandupdateQuery
method for awhile, albeit without the all-cached-variables capability).The text was updated successfully, but these errors were encountered: