Skip to content

Commit 3188d6a

Browse files
AnthonyMDevgh-action-runner
authored and
gh-action-runner
committed
Added Existential Any requirement (apollographql/apollo-ios-dev#379)
1 parent 522176b commit 3188d6a

File tree

55 files changed

+228
-223
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+228
-223
lines changed

Package.swift

+10-5
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,16 @@ let package = Package(
3434
],
3535
resources: [
3636
.copy("Resources/PrivacyInfo.xcprivacy")
37-
]
37+
],
38+
swiftSettings: [.enableUpcomingFeature("ExistentialAny")]
3839
),
3940
.target(
4041
name: "ApolloAPI",
4142
dependencies: [],
4243
resources: [
4344
.copy("Resources/PrivacyInfo.xcprivacy")
44-
]
45+
],
46+
swiftSettings: [.enableUpcomingFeature("ExistentialAny")]
4547
),
4648
.target(
4749
name: "ApolloSQLite",
@@ -51,7 +53,8 @@ let package = Package(
5153
],
5254
resources: [
5355
.copy("Resources/PrivacyInfo.xcprivacy")
54-
]
56+
],
57+
swiftSettings: [.enableUpcomingFeature("ExistentialAny")]
5558
),
5659
.target(
5760
name: "ApolloWebSocket",
@@ -60,14 +63,16 @@ let package = Package(
6063
],
6164
resources: [
6265
.copy("Resources/PrivacyInfo.xcprivacy")
63-
]
66+
],
67+
swiftSettings: [.enableUpcomingFeature("ExistentialAny")]
6468
),
6569
.target(
6670
name: "ApolloTestSupport",
6771
dependencies: [
6872
"Apollo",
6973
"ApolloAPI"
70-
]
74+
],
75+
swiftSettings: [.enableUpcomingFeature("ExistentialAny")]
7176
),
7277
.plugin(
7378
name: "Install CLI",

Sources/Apollo/ApolloClient.swift

+15-15
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ public enum CachePolicy: Hashable {
2525
///
2626
/// - Parameters:
2727
/// - result: The result of a performed operation. Will have a `GraphQLResult` with any parsed data and any GraphQL errors on `success`, and an `Error` on `failure`.
28-
public typealias GraphQLResultHandler<Data: RootSelectionSet> = (Result<GraphQLResult<Data>, Error>) -> Void
28+
public typealias GraphQLResultHandler<Data: RootSelectionSet> = (Result<GraphQLResult<Data>, any Error>) -> Void
2929

3030
/// The `ApolloClient` class implements the core API for Apollo by conforming to `ApolloClientProtocol`.
3131
public class ApolloClient {
3232

33-
let networkTransport: NetworkTransport
33+
let networkTransport: any NetworkTransport
3434

3535
public let store: ApolloStore
3636

@@ -50,7 +50,7 @@ public class ApolloClient {
5050
/// - Parameters:
5151
/// - networkTransport: A network transport used to send operations to a server.
5252
/// - store: A store used as a local cache. Note that if the `NetworkTransport` or any of its dependencies takes a store, you should make sure the same store is passed here so that it can be cleared properly.
53-
public init(networkTransport: NetworkTransport, store: ApolloStore) {
53+
public init(networkTransport: any NetworkTransport, store: ApolloStore) {
5454
self.networkTransport = networkTransport
5555
self.store = store
5656
}
@@ -73,18 +73,18 @@ public class ApolloClient {
7373
extension ApolloClient: ApolloClientProtocol {
7474

7575
public func clearCache(callbackQueue: DispatchQueue = .main,
76-
completion: ((Result<Void, Error>) -> Void)? = nil) {
76+
completion: ((Result<Void, any Error>) -> Void)? = nil) {
7777
self.store.clearCache(callbackQueue: callbackQueue, completion: completion)
7878
}
7979

8080
@discardableResult public func fetch<Query: GraphQLQuery>(
8181
query: Query,
8282
cachePolicy: CachePolicy = .default,
8383
contextIdentifier: UUID? = nil,
84-
context: RequestContext? = nil,
84+
context: (any RequestContext)? = nil,
8585
queue: DispatchQueue = .main,
8686
resultHandler: GraphQLResultHandler<Query.Data>? = nil
87-
) -> Cancellable {
87+
) -> (any Cancellable) {
8888
return self.networkTransport.send(operation: query,
8989
cachePolicy: cachePolicy,
9090
contextIdentifier: contextIdentifier,
@@ -109,7 +109,7 @@ extension ApolloClient: ApolloClientProtocol {
109109
query: Query,
110110
cachePolicy: CachePolicy = .default,
111111
refetchOnFailedUpdates: Bool = true,
112-
context: RequestContext? = nil,
112+
context: (any RequestContext)? = nil,
113113
callbackQueue: DispatchQueue = .main,
114114
resultHandler: @escaping GraphQLResultHandler<Query.Data>
115115
) -> GraphQLQueryWatcher<Query> {
@@ -128,10 +128,10 @@ extension ApolloClient: ApolloClientProtocol {
128128
mutation: Mutation,
129129
publishResultToStore: Bool = true,
130130
contextIdentifier: UUID? = nil,
131-
context: RequestContext? = nil,
131+
context: (any RequestContext)? = nil,
132132
queue: DispatchQueue = .main,
133133
resultHandler: GraphQLResultHandler<Mutation.Data>? = nil
134-
) -> Cancellable {
134+
) -> (any Cancellable) {
135135
return self.networkTransport.send(
136136
operation: mutation,
137137
cachePolicy: publishResultToStore ? .default : .fetchIgnoringCacheCompletely,
@@ -148,11 +148,11 @@ extension ApolloClient: ApolloClientProtocol {
148148
public func upload<Operation: GraphQLOperation>(
149149
operation: Operation,
150150
files: [GraphQLFile],
151-
context: RequestContext? = nil,
151+
context: (any RequestContext)? = nil,
152152
queue: DispatchQueue = .main,
153153
resultHandler: GraphQLResultHandler<Operation.Data>? = nil
154-
) -> Cancellable {
155-
guard let uploadingTransport = self.networkTransport as? UploadingNetworkTransport else {
154+
) -> (any Cancellable) {
155+
guard let uploadingTransport = self.networkTransport as? (any UploadingNetworkTransport) else {
156156
assertionFailure("Trying to upload without an uploading transport. Please make sure your network transport conforms to `UploadingNetworkTransport`.")
157157
queue.async {
158158
resultHandler?(.failure(ApolloClientError.noUploadTransport))
@@ -170,10 +170,10 @@ extension ApolloClient: ApolloClientProtocol {
170170

171171
public func subscribe<Subscription: GraphQLSubscription>(
172172
subscription: Subscription,
173-
context: RequestContext? = nil,
173+
context: (any RequestContext)? = nil,
174174
queue: DispatchQueue = .main,
175175
resultHandler: @escaping GraphQLResultHandler<Subscription.Data>
176-
) -> Cancellable {
176+
) -> any Cancellable {
177177
return self.networkTransport.send(operation: subscription,
178178
cachePolicy: .default,
179179
contextIdentifier: nil,
@@ -192,7 +192,7 @@ extension ApolloClient {
192192
public func watch<Query: GraphQLQuery>(
193193
query: Query,
194194
cachePolicy: CachePolicy = .default,
195-
context: RequestContext? = nil,
195+
context: (any RequestContext)? = nil,
196196
callbackQueue: DispatchQueue = .main,
197197
resultHandler: @escaping GraphQLResultHandler<Query.Data>
198198
) -> GraphQLQueryWatcher<Query> {

Sources/Apollo/ApolloClientProtocol.swift

+14-14
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public protocol ApolloClientProtocol: AnyObject {
1515
/// - Parameters:
1616
/// - callbackQueue: The queue to fall back on. Should default to the main queue.
1717
/// - completion: [optional] A completion closure to execute when clearing has completed. Should default to nil.
18-
func clearCache(callbackQueue: DispatchQueue, completion: ((Result<Void, Error>) -> Void)?)
18+
func clearCache(callbackQueue: DispatchQueue, completion: ((Result<Void, any Error>) -> Void)?)
1919

2020
/// Fetches a query from the server or from the local cache, depending on the current contents of the cache and the specified cache policy.
2121
///
@@ -30,9 +30,9 @@ public protocol ApolloClientProtocol: AnyObject {
3030
func fetch<Query: GraphQLQuery>(query: Query,
3131
cachePolicy: CachePolicy,
3232
contextIdentifier: UUID?,
33-
context: RequestContext?,
33+
context: (any RequestContext)?,
3434
queue: DispatchQueue,
35-
resultHandler: GraphQLResultHandler<Query.Data>?) -> Cancellable
35+
resultHandler: GraphQLResultHandler<Query.Data>?) -> (any Cancellable)
3636

3737
/// Watches a query by first fetching an initial result from the server or from the local cache, depending on the current contents of the cache and the specified cache policy. After the initial fetch, the returned query watcher object will get notified whenever any of the data the query result depends on changes in the local cache, and calls the result handler again with the new result.
3838
///
@@ -45,7 +45,7 @@ public protocol ApolloClientProtocol: AnyObject {
4545
/// - Returns: A query watcher object that can be used to control the watching behavior.
4646
func watch<Query: GraphQLQuery>(query: Query,
4747
cachePolicy: CachePolicy,
48-
context: RequestContext?,
48+
context: (any RequestContext)?,
4949
callbackQueue: DispatchQueue,
5050
resultHandler: @escaping GraphQLResultHandler<Query.Data>) -> GraphQLQueryWatcher<Query>
5151

@@ -62,9 +62,9 @@ public protocol ApolloClientProtocol: AnyObject {
6262
func perform<Mutation: GraphQLMutation>(mutation: Mutation,
6363
publishResultToStore: Bool,
6464
contextIdentifier: UUID?,
65-
context: RequestContext?,
65+
context: (any RequestContext)?,
6666
queue: DispatchQueue,
67-
resultHandler: GraphQLResultHandler<Mutation.Data>?) -> Cancellable
67+
resultHandler: GraphQLResultHandler<Mutation.Data>?) -> (any Cancellable)
6868

6969
/// Uploads the given files with the given operation.
7070
///
@@ -77,9 +77,9 @@ public protocol ApolloClientProtocol: AnyObject {
7777
/// - Returns: An object that can be used to cancel an in progress request.
7878
func upload<Operation: GraphQLOperation>(operation: Operation,
7979
files: [GraphQLFile],
80-
context: RequestContext?,
80+
context: (any RequestContext)?,
8181
queue: DispatchQueue,
82-
resultHandler: GraphQLResultHandler<Operation.Data>?) -> Cancellable
82+
resultHandler: GraphQLResultHandler<Operation.Data>?) -> (any Cancellable)
8383

8484
/// Subscribe to a subscription
8585
///
@@ -91,9 +91,9 @@ public protocol ApolloClientProtocol: AnyObject {
9191
/// - resultHandler: An optional closure that is called when mutation results are available or when an error occurs.
9292
/// - Returns: An object that can be used to cancel an in progress subscription.
9393
func subscribe<Subscription: GraphQLSubscription>(subscription: Subscription,
94-
context: RequestContext?,
94+
context: (any RequestContext)?,
9595
queue: DispatchQueue,
96-
resultHandler: @escaping GraphQLResultHandler<Subscription.Data>) -> Cancellable
96+
resultHandler: @escaping GraphQLResultHandler<Subscription.Data>) -> any Cancellable
9797
}
9898

9999
// MARK: - Backwards Compatibilty Extension
@@ -112,10 +112,10 @@ public extension ApolloClientProtocol {
112112
func fetch<Query: GraphQLQuery>(
113113
query: Query,
114114
cachePolicy: CachePolicy,
115-
context: RequestContext?,
115+
context: (any RequestContext)?,
116116
queue: DispatchQueue,
117117
resultHandler: GraphQLResultHandler<Query.Data>?
118-
) -> Cancellable {
118+
) -> (any Cancellable) {
119119
self.fetch(
120120
query: query,
121121
cachePolicy: cachePolicy,
@@ -138,10 +138,10 @@ public extension ApolloClientProtocol {
138138
func perform<Mutation: GraphQLMutation>(
139139
mutation: Mutation,
140140
publishResultToStore: Bool,
141-
context: RequestContext?,
141+
context: (any RequestContext)?,
142142
queue: DispatchQueue,
143143
resultHandler: GraphQLResultHandler<Mutation.Data>?
144-
) -> Cancellable {
144+
) -> (any Cancellable) {
145145
self.perform(
146146
mutation: mutation,
147147
publishResultToStore: publishResultToStore,

Sources/Apollo/ApolloErrorInterceptor.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ public protocol ApolloErrorInterceptor {
1414
/// - response: [optional] The response, if one was received
1515
/// - completion: The completion closure to fire when the operation has completed. Note that if you call `retry` on the chain, you will not want to call the completion block in this method.
1616
func handleErrorAsync<Operation: GraphQLOperation>(
17-
error: Error,
18-
chain: RequestChain,
19-
request: HTTPRequest<Operation>,
20-
response: HTTPResponse<Operation>?,
21-
completion: @escaping (Result<GraphQLResult<Operation.Data>, Error>) -> Void)
17+
error: any Error,
18+
chain: any RequestChain,
19+
request: HTTPRequest<Operation>,
20+
response: HTTPResponse<Operation>?,
21+
completion: @escaping (Result<GraphQLResult<Operation.Data>, any Error>) -> Void)
2222
}

Sources/Apollo/ApolloInterceptor.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public protocol ApolloInterceptor {
2020
/// - response: [optional] The response, if received
2121
/// - completion: The completion block to fire when data needs to be returned to the UI.
2222
func interceptAsync<Operation: GraphQLOperation>(
23-
chain: RequestChain,
23+
chain: any RequestChain,
2424
request: HTTPRequest<Operation>,
2525
response: HTTPResponse<Operation>?,
26-
completion: @escaping (Result<GraphQLResult<Operation.Data>, Error>) -> Void)
26+
completion: @escaping (Result<GraphQLResult<Operation.Data>, any Error>) -> Void)
2727
}

Sources/Apollo/ApolloStore.swift

+10-10
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ public protocol ApolloStoreSubscriber: AnyObject {
2222

2323
/// The `ApolloStore` class acts as a local cache for normalized GraphQL results.
2424
public class ApolloStore {
25-
private let cache: NormalizedCache
25+
private let cache: any NormalizedCache
2626
private let queue: DispatchQueue
2727

28-
internal var subscribers: [ApolloStoreSubscriber] = []
28+
internal var subscribers: [any ApolloStoreSubscriber] = []
2929

3030
/// Designated initializer
3131
/// - Parameters:
3232
/// - cache: An instance of `normalizedCache` to use to cache results.
3333
/// Defaults to an `InMemoryNormalizedCache`.
34-
public init(cache: NormalizedCache = InMemoryNormalizedCache()) {
34+
public init(cache: any NormalizedCache = InMemoryNormalizedCache()) {
3535
self.cache = cache
3636
self.queue = DispatchQueue(label: "com.apollographql.ApolloStore", attributes: .concurrent)
3737
}
@@ -47,7 +47,7 @@ public class ApolloStore {
4747
/// - Parameters:
4848
/// - callbackQueue: The queue to call the completion block on. Defaults to `DispatchQueue.main`.
4949
/// - completion: [optional] A completion block to be called after records are merged into the cache.
50-
public func clearCache(callbackQueue: DispatchQueue = .main, completion: ((Result<Void, Swift.Error>) -> Void)? = nil) {
50+
public func clearCache(callbackQueue: DispatchQueue = .main, completion: ((Result<Void, any Swift.Error>) -> Void)? = nil) {
5151
queue.async(flags: .barrier) {
5252
let result = Result { try self.cache.clear() }
5353
DispatchQueue.returnResultAsyncIfNeeded(
@@ -65,7 +65,7 @@ public class ApolloStore {
6565
/// to assist in de-duping cache hits for watchers.
6666
/// - callbackQueue: The queue to call the completion block on. Defaults to `DispatchQueue.main`.
6767
/// - completion: [optional] A completion block to be called after records are merged into the cache.
68-
public func publish(records: RecordSet, identifier: UUID? = nil, callbackQueue: DispatchQueue = .main, completion: ((Result<Void, Swift.Error>) -> Void)? = nil) {
68+
public func publish(records: RecordSet, identifier: UUID? = nil, callbackQueue: DispatchQueue = .main, completion: ((Result<Void, any Swift.Error>) -> Void)? = nil) {
6969
queue.async(flags: .barrier) {
7070
do {
7171
let changedKeys = try self.cache.merge(records: records)
@@ -90,7 +90,7 @@ public class ApolloStore {
9090
/// - Parameters:
9191
/// - subscriber: A subscriber to receive content change notificatons. To avoid a retain cycle,
9292
/// ensure you call `unsubscribe` on this subscriber before it goes out of scope.
93-
public func subscribe(_ subscriber: ApolloStoreSubscriber) {
93+
public func subscribe(_ subscriber: any ApolloStoreSubscriber) {
9494
queue.async(flags: .barrier) {
9595
self.subscribers.append(subscriber)
9696
}
@@ -101,7 +101,7 @@ public class ApolloStore {
101101
/// - Parameters:
102102
/// - subscriber: A subscribe that has previously been added via `subscribe`. To avoid retain cycles,
103103
/// call `unsubscribe` on all active subscribers before they go out of scope.
104-
public func unsubscribe(_ subscriber: ApolloStoreSubscriber) {
104+
public func unsubscribe(_ subscriber: any ApolloStoreSubscriber) {
105105
queue.async(flags: .barrier) {
106106
self.subscribers = self.subscribers.filter({ $0 !== subscriber })
107107
}
@@ -116,7 +116,7 @@ public class ApolloStore {
116116
public func withinReadTransaction<T>(
117117
_ body: @escaping (ReadTransaction) throws -> T,
118118
callbackQueue: DispatchQueue? = nil,
119-
completion: ((Result<T, Swift.Error>) -> Void)? = nil
119+
completion: ((Result<T, any Swift.Error>) -> Void)? = nil
120120
) {
121121
self.queue.async {
122122
do {
@@ -146,7 +146,7 @@ public class ApolloStore {
146146
public func withinReadWriteTransaction<T>(
147147
_ body: @escaping (ReadWriteTransaction) throws -> T,
148148
callbackQueue: DispatchQueue? = nil,
149-
completion: ((Result<T, Swift.Error>) -> Void)? = nil
149+
completion: ((Result<T, any Swift.Error>) -> Void)? = nil
150150
) {
151151
self.queue.async(flags: .barrier) {
152152
do {
@@ -201,7 +201,7 @@ public class ApolloStore {
201201
}
202202

203203
public class ReadTransaction {
204-
fileprivate let cache: NormalizedCache
204+
fileprivate let cache: any NormalizedCache
205205

206206
fileprivate lazy var loader: DataLoader<CacheKey, Record> = DataLoader(self.cache.loadRecords)
207207
fileprivate lazy var executor = GraphQLExecutor(

Sources/Apollo/AutomaticPersistedQueryInterceptor.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ public struct AutomaticPersistedQueryInterceptor: ApolloInterceptor {
3030
public init() {}
3131

3232
public func interceptAsync<Operation: GraphQLOperation>(
33-
chain: RequestChain,
33+
chain: any RequestChain,
3434
request: HTTPRequest<Operation>,
3535
response: HTTPResponse<Operation>?,
36-
completion: @escaping (Result<GraphQLResult<Operation.Data>, Error>) -> Void) {
36+
completion: @escaping (Result<GraphQLResult<Operation.Data>, any Error>) -> Void) {
3737

3838
guard let jsonRequest = request as? JSONRequest,
3939
jsonRequest.autoPersistQueries else {

Sources/Apollo/CacheReadInterceptor.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ public struct CacheReadInterceptor: ApolloInterceptor {
1818
}
1919

2020
public func interceptAsync<Operation: GraphQLOperation>(
21-
chain: RequestChain,
21+
chain: any RequestChain,
2222
request: HTTPRequest<Operation>,
2323
response: HTTPResponse<Operation>?,
24-
completion: @escaping (Result<GraphQLResult<Operation.Data>, Error>) -> Void) {
24+
completion: @escaping (Result<GraphQLResult<Operation.Data>, any Error>) -> Void) {
2525

2626
switch Operation.operationType {
2727
case .mutation,
@@ -115,8 +115,8 @@ public struct CacheReadInterceptor: ApolloInterceptor {
115115

116116
private func fetchFromCache<Operation: GraphQLOperation>(
117117
for request: HTTPRequest<Operation>,
118-
chain: RequestChain,
119-
completion: @escaping (Result<GraphQLResult<Operation.Data>, Error>) -> Void) {
118+
chain: any RequestChain,
119+
completion: @escaping (Result<GraphQLResult<Operation.Data>, any Error>) -> Void) {
120120

121121
self.store.load(request.operation) { loadResult in
122122
guard !chain.isCancelled else {

0 commit comments

Comments
 (0)