apollographql / apollo-link-state

✨ Manage your application's state with Apollo!
MIT License
1.4k stars 101 forks source link

Is it possible to have computed / derived state? #348

Open gregkerzhner opened 5 years ago

gregkerzhner commented 5 years ago

Is it possible to have calculated or derived data from inside the cache? Something similar to https://github.com/reduxjs/reselect?

Lets say I have a list of todos inside my cache, and I want to keep track of a field thats numberOfTodos. Can I set something up where numberOfTodos is calculated automatically based on todos.length? The only way I see to do this currently is to store numberOfTodos as an additional field in the cache which is not ideal because the goal of any state management system should be to store the least amount of data possible and have the rest be derived.