Hi
I'm using Apollo-iOS beta0.6.0.
Is the following behaviour expected?
returnCacheDataDontFetchapollo.watch(query: spacesQuery, cachePolicy: .returnCacheDataDontFetch , resultHandler: { (result , error ) in
if let error = error {
print(#function, "ERROR | An error occured: \(error)")
return
}
guard let edges = result?.data?.node?.asAccount?.spaces?.edges else {
print(#function, "ERROR | Could not retrieve trainer")
return
}
completionBlock(result,nil)
})
fetchIgnoringCacheData apollo.fetch(query: spacesQuery, cachePolicy: .fetchIgnoringCacheData, resultHandler: { (result ,
error ) in
if let error = error {
print(#function, "ERROR | An error occured: \(error)")
return
}
guard let _ = result?.data?.node?.asAccount?.spaces?.edges else {
print(#function, "ERROR | Could not retrieve trainer")
return
}
})
Do you store the GraphQLQueryWatcher you get from apollo.watch() somewhere? If not, the watcher will be immediately deinitialized.
See FrontPage app for an example.
Yes I'm storing GraphQLQueryWatcher in class level variable. It calls once I've fetched data.
Here are the steps for visualization purpose.
Ah, I think this is actually expected behavior (although we may want to rethink it). Basically, a watcher works by watching for a set of dependent keys. But it can only get these keys if it gets at least one valid response (either from the cache or from the network). Because your watch uses .returnCacheDataDontFetch, and the cache is initially empty, it will never get a valid response in that case.
Thanks for replying. It would be good if watcher notifies on any cache updates. As I see above is valid case, I'm using watcher only for loading/watching cached data changes, and fetch gets data from network.
As an alternative approach I'm thinking something like this.
fetch using returnCacheDataDontFetch and check for any cached data.
Most helpful comment
Thanks for replying. It would be good if watcher notifies on any cache updates. As I see above is valid case, I'm using watcher only for loading/watching cached data changes, and fetch gets data from network.
As an alternative approach I'm thinking something like this.
fetchusingreturnCacheDataDontFetchand check for any cached data.