-
Notifications
You must be signed in to change notification settings - Fork 57
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
fix: Cache write interceptor should gracefully handle missing cache records #439
Conversation
* Move chain cancellation check earlier * Do not expect cache records to be returned * Only write to cache if cache records were returned
✅ Deploy Preview for eclectic-pie-88a2ba canceled.
|
✅ Deploy Preview for apollo-ios-docc canceled.
|
@@ -7,17 +7,12 @@ import ApolloAPI | |||
public struct CacheWriteInterceptor: ApolloInterceptor { | |||
|
|||
public enum CacheWriteError: Error, LocalizedError { | |||
@available(*, deprecated, message: "Will be removed in a future version.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was deprecated because in the defer execution PR it was no longer being used. Had we caught this bug then it would never have been deprecated.
case noResponseToParse | ||
|
||
case missingCacheRecords |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arguably this is a breaking change but given the short availability of release 1.14.0
I don't see this as being too impactful. Like the deprecation of noResponseToParse
it would not have been introduced if we'd caught the bug earlier.
@@ -37,7 +32,11 @@ public struct CacheWriteInterceptor: ApolloInterceptor { | |||
request: HTTPRequest<Operation>, | |||
response: HTTPResponse<Operation>?, | |||
completion: @escaping (Result<GraphQLResult<Operation.Data>, any Error>) -> Void) { | |||
|
|||
|
|||
guard !chain.isCancelled else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've moved this earlier in the interceptAsync
logic because it makes sense that if the chain has already been cancelled you would not want to receive any response, nor should the interceptor chain proceed forward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGMT. Thanks for the fix!
39098c59 fix: Cache write interceptor should gracefully handle missing cache records (#439) git-subtree-dir: apollo-ios git-subtree-split: 39098c59162100bcc5a1483ca1a86b6f12e68c01
…cefully handle missing cache records git-subtree-dir: apollo-ios git-subtree-mainline: 0f86e27 git-subtree-split: 39098c59162100bcc5a1483ca1a86b6f12e68c01
The defer execution changes merged from PR #413 introduced a bug where the cache write interceptor would throw if no cache records were returned. This is incorrect as it is a valid response for the
data
key to be missing and only anerrors
key returned, such as in the case of a request error.This changeset is to allow the cache write interceptor to gracefully handle missing cache records and only publish records to the cache if they were returned from parsing.
noResponseToParse
errormissingCacheRecords
since it's no longer valid (breaking change)interceptAsync
ofCacheWriteInterceptor
method to return at the earliest pointThis was first reported as a result of #428 not getting a clean CI build.