Skip to content
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: legacyResponse property #456

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions apollo-ios/Sources/Apollo/HTTPResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ public class HTTPResponse<Operation: GraphQLOperation> {
/// [optional] The data as parsed into a `GraphQLResponse` for legacy caching purposes. If you're not using the
/// `JSONResponseParsingInterceptor`, you probably shouldn't be using this property.
@available(*, deprecated, message: "Do not use. This property will be removed in a future version.")
public var legacyResponse: GraphQLResponse<Operation.Data>? = nil

public var legacyResponse: GraphQLResponse<Operation.Data>? { _legacyResponse }
var _legacyResponse: GraphQLResponse<Operation.Data>? = nil

/// A set of cache records from the response
var cacheRecords: RecordSet?
public var cacheRecords: RecordSet?

/// Designated initializer
///
/// - Parameters:
Expand All @@ -49,6 +50,7 @@ extension HTTPResponse: Equatable where Operation.Data: Equatable {
lhs.httpResponse == rhs.httpResponse &&
lhs.rawData == rhs.rawData &&
lhs.parsedResponse == rhs.parsedResponse &&
lhs._legacyResponse == rhs._legacyResponse &&
lhs.cacheRecords == rhs.cacheRecords
}
}
Expand All @@ -60,6 +62,7 @@ extension HTTPResponse: Hashable where Operation.Data: Hashable {
hasher.combine(httpResponse)
hasher.combine(rawData)
hasher.combine(parsedResponse)
hasher.combine(_legacyResponse)
hasher.combine(cacheRecords)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,15 @@ public struct IncrementalJSONResponseParsingInterceptor: ApolloInterceptor {
}
}

createdResponse._legacyResponse = nil
Copy link
Member Author

@calvincestari calvincestari Aug 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the correct action to take here. There is nothing to set it to other than nil because this code path is for incremental responses. I think leaving the initial (partial) response in _legacyResponse is also incorrect because it doesn't match the result being returned. The 'legacy' part of the response logic could also be argued to mean pre-defer-support in which case nil again seems the correct choice.


parsedResult = currentResult
parsedCacheRecords = currentCacheRecords

} else {
let graphQLResponse = GraphQLResponse(
operation: request.operation,
body: body
)
let graphQLResponse = GraphQLResponse(operation: request.operation, body: body)
createdResponse._legacyResponse = graphQLResponse

let (result, cacheRecords) = try graphQLResponse.parseResult(withCachePolicy: request.cachePolicy)

parsedResult = result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ public struct JSONResponseParsingInterceptor: ApolloInterceptor {
}

let graphQLResponse = GraphQLResponse(operation: request.operation, body: body)
createdResponse._legacyResponse = graphQLResponse

let (result, cacheRecords) = try graphQLResponse.parseResult(withCachePolicy: request.cachePolicy)

createdResponse.parsedResponse = result
createdResponse.cacheRecords = cacheRecords

Expand Down
Loading