Skip to content

Commit

Permalink
Refactor legacyResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
calvincestari committed Aug 7, 2024
1 parent 5d4de74 commit 9940a43
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
7 changes: 5 additions & 2 deletions apollo-ios/Sources/Apollo/HTTPResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ 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
public var cacheRecords: RecordSet?

Expand Down Expand Up @@ -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 9940a43

Please sign in to comment.