Skip to content

[In Progress] Apollo iOS 2.0 - Base #645

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

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft
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
14 changes: 7 additions & 7 deletions Tests/ApolloInternalTestHelpers/InterceptorTester.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class InterceptorTester {
public func intercept<Operation>(
request: Apollo.HTTPRequest<Operation>,
response: Apollo.HTTPResponse<Operation>? = nil,
completion: @escaping (Result<HTTPResponse<Operation>?, any Error>) -> Void
completion: @escaping @Sendable (Result<HTTPResponse<Operation>?, any Error>) -> Void
) {
let requestChain = ResponseCaptureRequestChain<Operation>({ result in
completion(result)
Expand All @@ -38,13 +38,13 @@ fileprivate class ResponseCaptureRequestChain<T: GraphQLOperation>: RequestChain

func kickoff<Operation>(
request: Apollo.HTTPRequest<Operation>,
completion: @escaping (Result<Apollo.GraphQLResult<Operation.Data>, any Error>) -> Void
completion: @escaping GraphQLResultHandler<Operation.Data>
) {}

func proceedAsync<Operation>(
request: Apollo.HTTPRequest<Operation>,
response: Apollo.HTTPResponse<Operation>?,
completion: @escaping (Result<Apollo.GraphQLResult<Operation.Data>, any Error>) -> Void
completion: @escaping GraphQLResultHandler<Operation.Data>
) {
self.completion(.success(response as? HTTPResponse<T>))
}
Expand All @@ -53,7 +53,7 @@ fileprivate class ResponseCaptureRequestChain<T: GraphQLOperation>: RequestChain
request: HTTPRequest<Operation>,
response: HTTPResponse<Operation>?,
interceptor: any ApolloInterceptor,
completion: @escaping (Result<GraphQLResult<Operation.Data>, any Error>) -> Void
completion: @escaping GraphQLResultHandler<Operation.Data>
) {
self.completion(.success(response as? HTTPResponse<T>))
}
Expand All @@ -62,21 +62,21 @@ fileprivate class ResponseCaptureRequestChain<T: GraphQLOperation>: RequestChain

func retry<Operation>(
request: Apollo.HTTPRequest<Operation>,
completion: @escaping (Result<Apollo.GraphQLResult<Operation.Data>, any Error>) -> Void
completion: @escaping GraphQLResultHandler<Operation.Data>
) {}

func handleErrorAsync<Operation>(
_ error: any Error,
request: Apollo.HTTPRequest<Operation>,
response: Apollo.HTTPResponse<Operation>?,
completion: @escaping (Result<Apollo.GraphQLResult<Operation.Data>, any Error>) -> Void
completion: @escaping GraphQLResultHandler<Operation.Data>
) {
self.completion(.failure(error))
}

func returnValueAsync<Operation>(
for request: Apollo.HTTPRequest<Operation>,
value: Apollo.GraphQLResult<Operation.Data>,
completion: @escaping (Result<Apollo.GraphQLResult<Operation.Data>, any Error>) -> Void
completion: @escaping GraphQLResultHandler<Operation.Data>
) {}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import ApolloAPI
import Apollo
import Foundation

public extension SelectionSet {

var _rawData: [String: AnyHashable] { self.__data._data }
var _rawData: [String: DataDict.FieldValue] { self.__data._data }

func hasNullValue(forKey key: String) -> Bool {
guard let value = self.__data._data[key] else {
return false
}
return value == DataDict._NullValue
return value is NSNull
}

}
2 changes: 1 addition & 1 deletion Tests/ApolloPaginationTests/ForwardPaginationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ final class ForwardPaginationTests: XCTestCase, CacheDependentTesting {
"after": "Y3Vyc29yMg==",
]

let expectedVariables = Set(nextQuery.__variables?.values.compactMap { $0._jsonEncodableValue?._jsonValue } ?? [])
let expectedVariables = Set(nextQuery.__variables?.underlyingJsonValues ?? [])
let actualVariables = try await XCTUnwrapping(await pager.nextPageVarMap.keys.first)

XCTAssertEqual(expectedVariables.count, actualVariables.count)
Expand Down
4 changes: 2 additions & 2 deletions Tests/ApolloTests/ApolloClientOperationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ final class ApolloClientOperationTests: XCTestCase {
"__typename": "Review",
"stars": 3,
"commentary": ""
]
]
] as JSONValue
] as JSONValue
]

func test__performMutation_givenPublishResultToStore_true_publishResultsToStore() throws {
Expand Down
4 changes: 2 additions & 2 deletions Tests/ApolloTests/AutomaticPersistedQueriesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class AutomaticPersistedQueriesTests: XCTestCase {

guard
let httpBody = request.httpBody,
let jsonBody = try? JSONSerializationFormat.deserialize(data: httpBody) as? JSONObject else {
let jsonBody = try? JSONSerializationFormat.deserialize(data: httpBody) as JSONObject else {
fail(
"httpBody invalid",
location: SourceLocation(file: file, line: line)
Expand Down Expand Up @@ -199,7 +199,7 @@ class AutomaticPersistedQueriesTests: XCTestCase {
guard
let ext = ext,
let data = ext.data(using: .utf8),
let jsonBody = try? JSONSerializationFormat.deserialize(data: data) as? JSONObject
let jsonBody = try? JSONSerializationFormat.deserialize(data: data) as JSONObject
else {
fail(
"extensions json data should not be nil",
Expand Down
4 changes: 2 additions & 2 deletions Tests/ApolloTests/Cache/FetchQueryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class FetchQueryTests: XCTestCase, CacheDependentTesting {
"appearsIn": ["NEWHOPE", "EMPIRE", "JEDI"],
"__typename": "Droid"
]
]
] as JSONValue
]
}

Expand Down Expand Up @@ -411,7 +411,7 @@ class FetchQueryTests: XCTestCase, CacheDependentTesting {
let query = MockQuery.mock()

let serverRequestExpectation = server.expect(MockQuery<MockSelectionSet>.self) { request in
["data": [:]]
["data": [:] as JSONValue]
}

let resultObserver = makeResultObserver(for: query)
Expand Down
2 changes: 1 addition & 1 deletion Tests/ApolloTests/Cache/LoadQueryFromStoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@
"hero": [
"name": "R2-D2",
"__typename": "Droid",
"friends": [

Check failure on line 376 in Tests/ApolloTests/Cache/LoadQueryFromStoreTests.swift

View workflow job for this annotation

GitHub Actions / Apollo Unit Tests - macOS

conflicting arguments to generic parameter 'Element' ('NSNull' vs. 'CacheReference')

Check failure on line 376 in Tests/ApolloTests/Cache/LoadQueryFromStoreTests.swift

View workflow job for this annotation

GitHub Actions / Apollo Unit Tests - macOS

conflicting arguments to generic parameter 'Element' ('NSNull' vs. 'CacheReference')
CacheReference("hero.friends.0"),
NSNull(),
]
Expand Down Expand Up @@ -484,7 +484,7 @@
CacheReference("1003")
]
],
"1000": ["__typename": "Human", "name": ["dictionary": "badValues", "nested bad val": ["subdictionary": "some value"] ]
"1000": ["__typename": "Human", "name": ["dictionary": "badValues", "nested bad val": ["subdictionary": "some value"] ] as JSONValue
],
"1002": ["__typename": "Human", "name": "Han Solo"],
"1003": ["__typename": "Human", "name": "Leia Organa"],
Expand Down
10 changes: 5 additions & 5 deletions Tests/ApolloTests/Cache/ReadWriteFromStoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1816,11 +1816,11 @@ class ReadWriteFromStoreTests: XCTestCase, CacheDependentTesting, StoreLoading {
override class var __selections: [Selection] {[
.field("name", String.self),
.include(if: !"c", .field("friend", Friend.self)),
.include(if: !"d", .field("other", String.self))
.include(if: !"d", .field("other", String?.self))
]}
var name: String { __data["name"] }
var friend: Friend? { __data["friend"] }
var other: String? { __data["name"] }
var other: String? { __data["other"] }

convenience init(
name: String,
Expand Down Expand Up @@ -2686,13 +2686,13 @@ class ReadWriteFromStoreTests: XCTestCase, CacheDependentTesting, StoreLoading {
]
],
"1101": [
"__typename": "Human", "name": "Luke Skywalker", "id": "1101", "friends": []
"__typename": "Human", "name": "Luke Skywalker", "id": "1101", "friends": [] as JSONValue
],
"1002": [
"__typename": "Human", "name": "Han Solo", "id": "1002", "friends": []
"__typename": "Human", "name": "Han Solo", "id": "1002", "friends": [] as JSONValue
],
"1003": [
"__typename": "Human", "name": "Leia Organa", "id": "1003", "friends": []
"__typename": "Human", "name": "Leia Organa", "id": "1003", "friends": [] as JSONValue
],
])

Expand Down
4 changes: 2 additions & 2 deletions Tests/ApolloTests/Cache/StoreConcurrencyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class StoreConcurrencyTests: XCTestCase, CacheDependentTesting {
"name": "R2-D2",
"id": "2001",
"__typename": "Droid",
"friends": []
"friends": [] as JSONValue
]
])

Expand Down Expand Up @@ -331,7 +331,7 @@ class StoreConcurrencyTests: XCTestCase, CacheDependentTesting {
"name": "R2-D2",
"id": "2001",
"__typename": "Droid",
"friends": []
"friends": [] as JSONValue
]
])

Expand Down
28 changes: 14 additions & 14 deletions Tests/ApolloTests/Cache/WatchQueryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ class WatchQueryTests: XCTestCase, CacheDependentTesting {
["__typename": "Human", "name": "Leia Organa"],
]
]
]
] as JSONValue
]
}

Expand Down Expand Up @@ -598,7 +598,7 @@ class WatchQueryTests: XCTestCase, CacheDependentTesting {
["__typename": "Human", "id": "1003", "name": "Leia Organa"],
]
]
]
] as JSONValue
]
}

Expand Down Expand Up @@ -633,7 +633,7 @@ class WatchQueryTests: XCTestCase, CacheDependentTesting {
["__typename": "Human", "id": "1000"],
]
]
]
] as JSONValue
]
}

Expand Down Expand Up @@ -745,7 +745,7 @@ class WatchQueryTests: XCTestCase, CacheDependentTesting {
["__typename": "Human", "id": "1003", "name": "Leia Organa"],
]
]
]
] as JSONValue
]
}

Expand Down Expand Up @@ -781,7 +781,7 @@ class WatchQueryTests: XCTestCase, CacheDependentTesting {
["__typename": "Human", "id": "1000"],
]
]
]
] as JSONValue
]
}

Expand All @@ -799,7 +799,7 @@ class WatchQueryTests: XCTestCase, CacheDependentTesting {
["__typename": "Human", "id": "1000", "name": "Luke Skywalker"],
]
]
]
] as JSONValue
]
}

Expand Down Expand Up @@ -913,7 +913,7 @@ class WatchQueryTests: XCTestCase, CacheDependentTesting {
["__typename": "Human", "id": "1003", "name": "Leia Organa"],
]
]
]
] as JSONValue
]
}

Expand Down Expand Up @@ -949,7 +949,7 @@ class WatchQueryTests: XCTestCase, CacheDependentTesting {
["__typename": "Human", "id": "1000"],
]
]
]
] as JSONValue
]
}

Expand Down Expand Up @@ -1044,7 +1044,7 @@ class WatchQueryTests: XCTestCase, CacheDependentTesting {
["__typename": "Human", "name": "Leia Organa"],
]
]
]
] as JSONValue
]
}

Expand Down Expand Up @@ -1283,7 +1283,7 @@ class WatchQueryTests: XCTestCase, CacheDependentTesting {
["__typename": "Human", "id": "1000"],
]
]
]
] as JSONValue
]
}

Expand Down Expand Up @@ -1595,7 +1595,7 @@ class WatchQueryTests: XCTestCase, CacheDependentTesting {
["__typename": "Human", "id": "1000", "name": "Luke Skywalker"],
]
]
]
] as JSONValue
]
}

Expand Down Expand Up @@ -1730,7 +1730,7 @@ class WatchQueryTests: XCTestCase, CacheDependentTesting {
["__typename": "Human", "id": "1000", "name": "Luke Skywalker"],
]
]
]
] as JSONValue
]
}

Expand Down Expand Up @@ -1782,7 +1782,7 @@ class WatchQueryTests: XCTestCase, CacheDependentTesting {
["__typename": "Human", "id": "1002", "name": "Han Solo"],
]
]
]
] as JSONValue
]
}

Expand Down Expand Up @@ -1884,7 +1884,7 @@ class WatchQueryTests: XCTestCase, CacheDependentTesting {
["__typename": "Human", "id": "1000", "name": "Luke Skywalker"],
]
]
]
] as JSONValue
]
}

Expand Down
9 changes: 7 additions & 2 deletions Tests/ApolloTests/CacheKeyForFieldTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import XCTest
@testable import Apollo
import ApolloAPI

class CacheKeyForFieldTests: XCTestCase {
func testFieldWithNameOnly() {
Expand Down Expand Up @@ -30,7 +31,9 @@ class CacheKeyForFieldTests: XCTestCase {
func testFieldWithNestedNullArgument() throws {
let actual = CacheKeyForField(
named: "hero",
arguments: ["nested": ["foo": 1, "bar": NSNull()]]
arguments: [
"nested": ["foo": 1, "bar": NSNull()] as JSONValue
]
)
XCTAssertEqual(actual, "hero([nested:bar:null,foo:1])")
}
Expand All @@ -43,7 +46,9 @@ class CacheKeyForFieldTests: XCTestCase {
func testFieldWithDictionaryArgument() throws {
let actual = CacheKeyForField(
named: "hero",
arguments: ["nested": ["foo": 1, "bar": "2"]]
arguments: [
"nested": ["foo": 1, "bar": "2"] as JSONValue
]
)
XCTAssertEqual(actual, "hero([nested:bar:2,foo:1])")
}
Expand Down
1 change: 1 addition & 0 deletions Tests/ApolloTests/DataDictMergingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,4 @@ class DataDictMergingTests: XCTestCase {
}

}

2 changes: 2 additions & 0 deletions Tests/ApolloTests/DeferTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ final class DeferTests: XCTestCase {
override class var __selections: [Selection] {[
.field("genres", [String].self),
]}

var genres: [String] { __data["genres"] }
}

class Character: AbstractMockSelectionSet<Character.Fragments, MockSchemaMetadata> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class NetworkResponseExecutionSource_OpaqueObjectDataWrapper_Tests: XCTestCase {
}
""".data(using: .utf8)!

let deserialized = try JSONSerializationFormat.deserialize(data: data) as! JSONObject
let deserialized = try JSONSerializationFormat.deserialize(data: data) as JSONObject
let objectData = subject.opaqueObjectDataWrapper(for: deserialized)

// when
Expand Down
Loading
Loading