awslabs / aws-mobile-appsync-sdk-ios

iOS SDK for AWS AppSync.
https://awslabs.github.io/aws-mobile-appsync-sdk-ios/
Other
262 stars 128 forks source link

fix: Repopulate records table with empty QUERY_ROOT after caches are cleared #535

Closed jellybeansoup closed 2 years ago

jellybeansoup commented 2 years ago

Issue #, if available:

92 (kinda?)

Description of changes: As part of working around an issue allowing optimistic updates of query results that haven't been retrieved from the service, @palpatim introduced code to pre-populate an empty table with an empty QUERY_ROOT, resolving the issue. However the issue resurfaces if at any point the caches are cleared, as the table is not then repopulated with the empty QUERY_ROOT.

So if, for example, a user installs an app for the first time and log into an account backed by AWS App Sync, the existing workaround correctly ensures that optimistic updates don't fail when the underlying query results have not been fetched from the service, but if that user were to sign out (causing the caches to be cleared) and then into another account, the workaround is no longer in place, and optimistic updates will fail.

This PR introduces changes to repopulate the cache with the empty QUERY_ROOT immediately after clearing it, thereby ensuring that optimistic updates do not fail after calling clearCaches(). The requisite tests have also been updated to showcase the issue, and show that it is resolved.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

atierian commented 2 years ago

Thanks for opening this PR @jellybeansoup. We'll review and get back to you on this shortly.

jellybeansoup commented 2 years ago

Thanks so much, @lawmicha. I've cherry-picked the requested changes; really should've picked up on that myself 😅