From 9940a437b31e260f0b4e7e3372c1e7034e423040 Mon Sep 17 00:00:00 2001 From: Calvin Cestari Date: Wed, 7 Aug 2024 15:52:01 -0700 Subject: [PATCH] Refactor legacyResponse --- apollo-ios/Sources/Apollo/HTTPResponse.swift | 7 +++++-- .../IncrementalJSONResponseParsingInterceptor.swift | 9 +++++---- .../Sources/Apollo/JSONResponseParsingInterceptor.swift | 3 ++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/apollo-ios/Sources/Apollo/HTTPResponse.swift b/apollo-ios/Sources/Apollo/HTTPResponse.swift index 24b1bbab1..2b2cb27f7 100644 --- a/apollo-ios/Sources/Apollo/HTTPResponse.swift +++ b/apollo-ios/Sources/Apollo/HTTPResponse.swift @@ -19,8 +19,9 @@ public class HTTPResponse { /// [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? = nil - + public var legacyResponse: GraphQLResponse? { _legacyResponse } + var _legacyResponse: GraphQLResponse? = nil + /// A set of cache records from the response public var cacheRecords: RecordSet? @@ -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 } } @@ -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) } } diff --git a/apollo-ios/Sources/Apollo/IncrementalJSONResponseParsingInterceptor.swift b/apollo-ios/Sources/Apollo/IncrementalJSONResponseParsingInterceptor.swift index 4a16b9d73..219bdbde7 100644 --- a/apollo-ios/Sources/Apollo/IncrementalJSONResponseParsingInterceptor.swift +++ b/apollo-ios/Sources/Apollo/IncrementalJSONResponseParsingInterceptor.swift @@ -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 diff --git a/apollo-ios/Sources/Apollo/JSONResponseParsingInterceptor.swift b/apollo-ios/Sources/Apollo/JSONResponseParsingInterceptor.swift index 46f774a4d..16c8fc31b 100644 --- a/apollo-ios/Sources/Apollo/JSONResponseParsingInterceptor.swift +++ b/apollo-ios/Sources/Apollo/JSONResponseParsingInterceptor.swift @@ -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