-
Notifications
You must be signed in to change notification settings - Fork 130
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
Regression in behavior of queries against empty cache #181
Comments
Hey @palpatim One of our app models is intended to be used offline-only and because of that, we use the .returnCacheDataDontFetch cache-policy combined with optimistic updates for requests and queries. Can we assert that once this issue gets fixed that could be possible? |
I don't have specific tests around that use case, but yes, that should work as expected. Do note that optimistic updates against an empty cache will still require you to populate a list structure to begin with, as in this example from appSyncClient.perform(
mutation: addPost,
queue: MutationOptimisticUpdateTests.mutationQueue,
optimisticUpdate: { transaction in
guard let transaction = transaction else {
XCTFail("Optimistic update transaction unexpectedly nil")
return
}
do {
try transaction.update(query: ListPostsQuery()) { data in
// Note this line checks for a `nil` list structure -----v
var listPosts: [ListPostsQuery.Data.ListPost?] = data.listPosts ?? []
listPosts.append(newPost)
data.listPosts = listPosts
}
// The `update` is synchronous, so we can fulfill after the block completes
optimisticUpdatePerformed.fulfill()
} catch {
XCTFail("Unexpected error performing optimistic update: \(error)")
}
}) |
This fix is released in 2.10.1. |
Describe the bug
PR #177, which is intended to fix #92 and #101, regresses the behavior of queries against an empty cache.
To Reproduce
Steps to reproduce the behavior:
FetchQueryTests.testReturnCacheDataAndFetch
to a test namedtestReturnCacheDataAndFetchWithMissingData
FetchQueryTests
test*WithMissingData
to set the initialData to:nil
. That causes the.returnCacheDataDontFetch
policy to return an empty result instead of anil
, and causes.returnCacheDataElseFetch
to return an empty result instead of falling through to server results. (This last is similar behavior as described in returnCacheDataElseFetch returning nil instead of fetching #90, except that it was previously returningnil
and not falling through to server results)Expected behavior
nil
result, or an empty result set) for a query should behave as follows:.returnCacheDataAndFetch
: Does not return a value from cache, returns results from server.returnCacheDataDontFetch
: Return anil
value, cease processing.returnCacheDataElseFetch
: Does not return a value from cache, returns results from serverObviously, whatever fix is in place should also maintain the correct behavior for a cache that contains a query hit:
.returnCacheDataAndFetch
: Returns a value from cache, and returns results from server.returnCacheDataDontFetch
: Return a value from cache, cease processing.returnCacheDataElseFetch
: Return a value from cache, cease processingEssentially we now have different conditions leading to a cache miss that we need to handle:
The text was updated successfully, but these errors were encountered: