-
Notifications
You must be signed in to change notification settings - Fork 114
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
When evicting an entity from the cache, the list becomes empty when it is nested in an object. #498
Comments
You can inspect what is happening by inspecting the contents of the cache. (e.g. client.cache.store.keys.forEach((key) {
print(key);
});
print(client.cache.store.get('Query')); The cache stores the results of the queries like this:
and then each entry like this:
So, when you remove a Pokemon entry from the cache, it is still referenced in the queries. So, when the data is denormalized, this can lead to issues. For lists, ferry just ignores the invalid reference, see
and
This is what you are seeing in the non-nested case. For the nested case, the invalid reference happens in a nested object, and we throw a PartialDataException exception here since the referenced object is supposed to be non-nullable. I can see why this behavior can be confusing. |
So, evict() does not preserve referential integrity and should be used with caution. I can imagine improvements in handling danging references though, ferry probably should treat nested objects in lists with dangling references the same is direct dangling references in lists. I could also see a For a workaround for now, you can use writeQuery() to manually remove the evicted item from the the nested query. |
Yes it could be nice to do something like that: .where((data) => !isDanglingReference(data, config) && !isPartial) where
This is actually what I'm trying to move away from. I'm having a bunch of different queries that fetch a list of |
the Object? denormalizeNode({
required SelectionSetNode? selectionSet,
required Object? dataForNode,
required NormalizationConfig config,
}) {
if (dataForNode == null) return null;
if (dataForNode is List) {
final newList = <Object?>[];
final reachableData = dataForNode
.where((data) => !isDanglingReference(data, config));
for(final node in reachableDate) {
try{
final denormalizedSubNode = denormalizeNode(
selectionSet: selectionSet,
dataForNode: node,
config: config);
newList.add(denormalizedSubNode);
} on PartialDataException {
// ignore list items with partial data
}
}
...
} The config actually has a parameter to set whether partial data is allowed or not, but for ferry we have to set it to true, as ferry is strongly typed an partial data would lead to exceptions further down the line when trying the map the denormalized data to the typed objects. |
I have this code (you can also check out https://github.com/ValentinVignal/flutter_app_stable/tree/ferry/cache-and-fragment)
With 2 queries:
Notice that
pokemons
returns a list ofPokemon
(with an id) whilenestedPokemon
returns a list ofNestedPokemon
pokemon (that doesn't have an id)I have an application that:
Code
When an entity is deleted from the cache, the UI is rebuilt.
Video
Screen.Recording.2023-03-06.at.3.50.31.PM.mov
I would expect both lists to behave as the first one (non-nested)
The text was updated successfully, but these errors were encountered: