Skip to content

Commit

Permalink
fix: legacyResponse property (#456)
Browse files Browse the repository at this point in the history
  • Loading branch information
calvincestari authored Aug 8, 2024
1 parent 0eda6f3 commit 7e053b8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
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

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

0 comments on commit 7e053b8

Please sign in to comment.