-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Add an option in ApolloClient constructor to return a deep copy of query results (or a way to globally transform results after the caching step) #11841
Comments
I am facing the same issue in my nextjs application, and I think it is solvable by reintroducing freezeResult option which was present in apollo 2.6 and got removed in 3.0 |
Hi there, we've talked about this internally and this is something we're not going to introduce to the Reintroducing the option to turn off As for the general notion of returning a modifiable copy - that would end up being something that is actively discouraged in most frameworks, as most frameworks have their own methods of tracking state changes that would be distinct from that - in React for example it's strictly forbidden to have any kind of mutable object (never do that in your Next app!). Every state change has to go through React's There is also other behaviour that would be problematic or unclear here - in the case of any kind of cache update, you'd lose all changes you made to that object locally, because you would receive a new full copy of the cached value. That would probably not be very desirable in most cases. Generally, we expose methods that allow you to modify the cache, and those changes will always propagate to your components. But even then keep in mind that new data from the network will override your cache modifications. I believe that in the case of vue-apollo, that data being stored in Lastly, something like a |
Hi @shyamayadav154 - since this is a feature request and one that exists over at apollographql/apollo-feature-requests#372 I will close this issue out, but please feel free to add any other thoughts over on that issue. Thanks! |
Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This issue is to bring the attention toward issue that is open in apollographql github repo
apollographql/apollo-feature-requests#372
Hello,
With the release of AC2.6 (and it's the same with AC3), all queries results are now read only.
However, there is use cases where it's handy and intuitive to mutate the query result (which is different than mutate the cache directly).
For example, when using VueJs, dev could write something like this:
With vue-apollo, userMe query result is stored directly in data.userMe and, in VueJs, data is the dedicated place for mutable data (aka mutate them will trigger a re-render). So dev will intuitively want to mutate the query result, like any other variables in data.
But, because the result object is now read only, for a real world example, when the dev will bind userMe.name to an , a console error will appears saying that name is read only.
Currently, dev have to workaround that on every query this way:
To solve that while still preserving the cache from direct mutation, an option deepCopyResults (for example) could be added in ApolloClient constructor.
Another way to solve that could be to add an option transformResults (for example) which accept a function to transform results after they are stored in the cache (a thing that a network link can't do if I read the documentation correctly). This solution may be more interesting because it allow for any global transformation after the caching step (covering more use cases).
Wdyt? After all, there is already assumeImmutableResults so why not deepCopyResults or transformResults? 🙃
The text was updated successfully, but these errors were encountered: