-
Notifications
You must be signed in to change notification settings - Fork 740
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
Why is there no fetchElseReturnCacheData policy? #392
Comments
Good question! I think it's just not been implemented. I think this would be a solid enhancement though. I'll put it on the list, but it's a bit of a long list so I don't have an ETA for you. |
So after some looking into this, there is the Does that cover the functionality you're looking for here, or is there a benefit I'm missing to trying the fetch first? |
@designatednerd Does that make sense? |
The what definitely makes sense - I'm not quite clear on why that's a better user experience than starting with old data and refreshing. I think getting a better understanding of that would probably help me prioritize this. |
I agree that in general that's a better user experience but I'm currently adopting requirements from an android app that behaves in this way which is why I requested the feature. I'm currently doing this myself using RxSwift but i rather have native support. Sorry i can't give you a better reason :( |
OK - that helps though, the fact that it's trying to match an android experience with an option that doesn't exist on iOS. I'll see what I can do, though I don't have a timeline for you, I've got some other stuff I'd like to get shipped this week. |
@ValCanBuild - can you share Your current approach with RxSwift? I would alos love to see this feature in a native way. |
@pgawlowski I've not checked this code still runs against latest Swift and Apollo versions but it went something like this: func fetch<Query: GraphQLQuery>(_ query: Query, cachePolicy: CachePolicy = Apollo.CachePolicy.fetchIgnoringCacheData) -> Single<Query.Data> {
return Single.deferred { [unowned self] in
self.apollo.rxfetch(query: query, cachePolicy: cachePolicy)
}
.catchError { [unowned self] in
let retryFetchFromCache = $0.isConnectivityError && cachePolicy == Apollo.CachePolicy.fetchIgnoringCacheData
if retryFetchFromCache {
return self.apollo.rxfetch(query: query, cachePolicy: Apollo.CachePolicy.returnCacheDataElseFetch)
} else {
return .error($0)
}
}
} |
Thanks for the example in RxSwift. I'm looking at some changes to the networking stack now, I'll have to think on making this official since it's a totally different order than our other operations, but the changes would at least allow you to build this yourself reasonably easily. |
@designatednerd - I can't promise (cause I am already overloaded with work) but I might be able to prepare some PR here, since I need this feature :) I've already checked the source code and I think this feature might be easy to introduce. |
Hey @pgawlowski I'm gonna have an RFC up for a new network architecture sometime this week or next - you may want to hold off until that's up since it'll change how this all works. |
@pgawlowski @ValCanBuild Please check out the RFC for networking changes at #1340 - we're not going to add this as a default option, but it should be fairly simple to reorder interceptors in order to facilitate the same idea. |
OK, getting ready to beta this but you should be able to do this with custom ordering of the provided interceptors and/or a custom interceptor. Please see #1341 for the current implementation. |
The networking stack is now available as a beta at |
Hello, first time user of Apollo-iOS here, though I have been using Apollo android for quite some time.
In Apollo Android there is NetworkFirst
ResponseFetcher
(that I assume to be an equivalent ofApollo.CachePolicy
in iOS). The description of this fetcher isThis has been very useful to me in Android for showing good offline state when calls fail. I was wondering why there isn't an equivalent functionality in iOS. Is it on purpose or has it just not been requested?
The text was updated successfully, but these errors were encountered: