Skip to content

Commit

Permalink
Squashed 'apollo-ios/' changes from 522176b7..3188d6a6
Browse files Browse the repository at this point in the history
3188d6a6 Added Existential Any requirement (#379)

git-subtree-dir: apollo-ios
git-subtree-split: 3188d6a60184e826ac51a526d35a362aeba2cb9d
  • Loading branch information
gh-action-runner authored and gh-action-runner committed Jun 6, 2024
1 parent c2974f5 commit f957243
Show file tree
Hide file tree
Showing 55 changed files with 228 additions and 223 deletions.
15 changes: 10 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ let package = Package(
],
resources: [
.copy("Resources/PrivacyInfo.xcprivacy")
]
],
swiftSettings: [.enableUpcomingFeature("ExistentialAny")]
),
.target(
name: "ApolloAPI",
dependencies: [],
resources: [
.copy("Resources/PrivacyInfo.xcprivacy")
]
],
swiftSettings: [.enableUpcomingFeature("ExistentialAny")]
),
.target(
name: "ApolloSQLite",
Expand All @@ -51,7 +53,8 @@ let package = Package(
],
resources: [
.copy("Resources/PrivacyInfo.xcprivacy")
]
],
swiftSettings: [.enableUpcomingFeature("ExistentialAny")]
),
.target(
name: "ApolloWebSocket",
Expand All @@ -60,14 +63,16 @@ let package = Package(
],
resources: [
.copy("Resources/PrivacyInfo.xcprivacy")
]
],
swiftSettings: [.enableUpcomingFeature("ExistentialAny")]
),
.target(
name: "ApolloTestSupport",
dependencies: [
"Apollo",
"ApolloAPI"
]
],
swiftSettings: [.enableUpcomingFeature("ExistentialAny")]
),
.plugin(
name: "Install CLI",
Expand Down
30 changes: 15 additions & 15 deletions Sources/Apollo/ApolloClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public enum CachePolicy: Hashable {
///
/// - Parameters:
/// - 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`.
public typealias GraphQLResultHandler<Data: RootSelectionSet> = (Result<GraphQLResult<Data>, Error>) -> Void
public typealias GraphQLResultHandler<Data: RootSelectionSet> = (Result<GraphQLResult<Data>, any Error>) -> Void

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

let networkTransport: NetworkTransport
let networkTransport: any NetworkTransport

public let store: ApolloStore

Expand All @@ -50,7 +50,7 @@ public class ApolloClient {
/// - Parameters:
/// - networkTransport: A network transport used to send operations to a server.
/// - 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.
public init(networkTransport: NetworkTransport, store: ApolloStore) {
public init(networkTransport: any NetworkTransport, store: ApolloStore) {
self.networkTransport = networkTransport
self.store = store
}
Expand All @@ -73,18 +73,18 @@ public class ApolloClient {
extension ApolloClient: ApolloClientProtocol {

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

@discardableResult public func fetch<Query: GraphQLQuery>(
query: Query,
cachePolicy: CachePolicy = .default,
contextIdentifier: UUID? = nil,
context: RequestContext? = nil,
context: (any RequestContext)? = nil,
queue: DispatchQueue = .main,
resultHandler: GraphQLResultHandler<Query.Data>? = nil
) -> Cancellable {
) -> (any Cancellable) {
return self.networkTransport.send(operation: query,
cachePolicy: cachePolicy,
contextIdentifier: contextIdentifier,
Expand All @@ -109,7 +109,7 @@ extension ApolloClient: ApolloClientProtocol {
query: Query,
cachePolicy: CachePolicy = .default,
refetchOnFailedUpdates: Bool = true,
context: RequestContext? = nil,
context: (any RequestContext)? = nil,
callbackQueue: DispatchQueue = .main,
resultHandler: @escaping GraphQLResultHandler<Query.Data>
) -> GraphQLQueryWatcher<Query> {
Expand All @@ -128,10 +128,10 @@ extension ApolloClient: ApolloClientProtocol {
mutation: Mutation,
publishResultToStore: Bool = true,
contextIdentifier: UUID? = nil,
context: RequestContext? = nil,
context: (any RequestContext)? = nil,
queue: DispatchQueue = .main,
resultHandler: GraphQLResultHandler<Mutation.Data>? = nil
) -> Cancellable {
) -> (any Cancellable) {
return self.networkTransport.send(
operation: mutation,
cachePolicy: publishResultToStore ? .default : .fetchIgnoringCacheCompletely,
Expand All @@ -148,11 +148,11 @@ extension ApolloClient: ApolloClientProtocol {
public func upload<Operation: GraphQLOperation>(
operation: Operation,
files: [GraphQLFile],
context: RequestContext? = nil,
context: (any RequestContext)? = nil,
queue: DispatchQueue = .main,
resultHandler: GraphQLResultHandler<Operation.Data>? = nil
) -> Cancellable {
guard let uploadingTransport = self.networkTransport as? UploadingNetworkTransport else {
) -> (any Cancellable) {
guard let uploadingTransport = self.networkTransport as? (any UploadingNetworkTransport) else {
assertionFailure("Trying to upload without an uploading transport. Please make sure your network transport conforms to `UploadingNetworkTransport`.")
queue.async {
resultHandler?(.failure(ApolloClientError.noUploadTransport))
Expand All @@ -170,10 +170,10 @@ extension ApolloClient: ApolloClientProtocol {

public func subscribe<Subscription: GraphQLSubscription>(
subscription: Subscription,
context: RequestContext? = nil,
context: (any RequestContext)? = nil,
queue: DispatchQueue = .main,
resultHandler: @escaping GraphQLResultHandler<Subscription.Data>
) -> Cancellable {
) -> any Cancellable {
return self.networkTransport.send(operation: subscription,
cachePolicy: .default,
contextIdentifier: nil,
Expand All @@ -192,7 +192,7 @@ extension ApolloClient {
public func watch<Query: GraphQLQuery>(
query: Query,
cachePolicy: CachePolicy = .default,
context: RequestContext? = nil,
context: (any RequestContext)? = nil,
callbackQueue: DispatchQueue = .main,
resultHandler: @escaping GraphQLResultHandler<Query.Data>
) -> GraphQLQueryWatcher<Query> {
Expand Down
28 changes: 14 additions & 14 deletions Sources/Apollo/ApolloClientProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public protocol ApolloClientProtocol: AnyObject {
/// - Parameters:
/// - callbackQueue: The queue to fall back on. Should default to the main queue.
/// - completion: [optional] A completion closure to execute when clearing has completed. Should default to nil.
func clearCache(callbackQueue: DispatchQueue, completion: ((Result<Void, Error>) -> Void)?)
func clearCache(callbackQueue: DispatchQueue, completion: ((Result<Void, any Error>) -> Void)?)

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

/// 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.
///
Expand All @@ -45,7 +45,7 @@ public protocol ApolloClientProtocol: AnyObject {
/// - Returns: A query watcher object that can be used to control the watching behavior.
func watch<Query: GraphQLQuery>(query: Query,
cachePolicy: CachePolicy,
context: RequestContext?,
context: (any RequestContext)?,
callbackQueue: DispatchQueue,
resultHandler: @escaping GraphQLResultHandler<Query.Data>) -> GraphQLQueryWatcher<Query>

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

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

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

// MARK: - Backwards Compatibilty Extension
Expand All @@ -112,10 +112,10 @@ public extension ApolloClientProtocol {
func fetch<Query: GraphQLQuery>(
query: Query,
cachePolicy: CachePolicy,
context: RequestContext?,
context: (any RequestContext)?,
queue: DispatchQueue,
resultHandler: GraphQLResultHandler<Query.Data>?
) -> Cancellable {
) -> (any Cancellable) {
self.fetch(
query: query,
cachePolicy: cachePolicy,
Expand All @@ -138,10 +138,10 @@ public extension ApolloClientProtocol {
func perform<Mutation: GraphQLMutation>(
mutation: Mutation,
publishResultToStore: Bool,
context: RequestContext?,
context: (any RequestContext)?,
queue: DispatchQueue,
resultHandler: GraphQLResultHandler<Mutation.Data>?
) -> Cancellable {
) -> (any Cancellable) {
self.perform(
mutation: mutation,
publishResultToStore: publishResultToStore,
Expand Down
10 changes: 5 additions & 5 deletions Sources/Apollo/ApolloErrorInterceptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public protocol ApolloErrorInterceptor {
/// - response: [optional] The response, if one was received
/// - 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.
func handleErrorAsync<Operation: GraphQLOperation>(
error: Error,
chain: RequestChain,
request: HTTPRequest<Operation>,
response: HTTPResponse<Operation>?,
completion: @escaping (Result<GraphQLResult<Operation.Data>, Error>) -> Void)
error: any Error,
chain: any RequestChain,
request: HTTPRequest<Operation>,
response: HTTPResponse<Operation>?,
completion: @escaping (Result<GraphQLResult<Operation.Data>, any Error>) -> Void)
}
4 changes: 2 additions & 2 deletions Sources/Apollo/ApolloInterceptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public protocol ApolloInterceptor {
/// - response: [optional] The response, if received
/// - completion: The completion block to fire when data needs to be returned to the UI.
func interceptAsync<Operation: GraphQLOperation>(
chain: RequestChain,
chain: any RequestChain,
request: HTTPRequest<Operation>,
response: HTTPResponse<Operation>?,
completion: @escaping (Result<GraphQLResult<Operation.Data>, Error>) -> Void)
completion: @escaping (Result<GraphQLResult<Operation.Data>, any Error>) -> Void)
}
20 changes: 10 additions & 10 deletions Sources/Apollo/ApolloStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ public protocol ApolloStoreSubscriber: AnyObject {

/// The `ApolloStore` class acts as a local cache for normalized GraphQL results.
public class ApolloStore {
private let cache: NormalizedCache
private let cache: any NormalizedCache
private let queue: DispatchQueue

internal var subscribers: [ApolloStoreSubscriber] = []
internal var subscribers: [any ApolloStoreSubscriber] = []

/// Designated initializer
/// - Parameters:
/// - cache: An instance of `normalizedCache` to use to cache results.
/// Defaults to an `InMemoryNormalizedCache`.
public init(cache: NormalizedCache = InMemoryNormalizedCache()) {
public init(cache: any NormalizedCache = InMemoryNormalizedCache()) {
self.cache = cache
self.queue = DispatchQueue(label: "com.apollographql.ApolloStore", attributes: .concurrent)
}
Expand All @@ -47,7 +47,7 @@ public class ApolloStore {
/// - Parameters:
/// - callbackQueue: The queue to call the completion block on. Defaults to `DispatchQueue.main`.
/// - completion: [optional] A completion block to be called after records are merged into the cache.
public func clearCache(callbackQueue: DispatchQueue = .main, completion: ((Result<Void, Swift.Error>) -> Void)? = nil) {
public func clearCache(callbackQueue: DispatchQueue = .main, completion: ((Result<Void, any Swift.Error>) -> Void)? = nil) {
queue.async(flags: .barrier) {
let result = Result { try self.cache.clear() }
DispatchQueue.returnResultAsyncIfNeeded(
Expand All @@ -65,7 +65,7 @@ public class ApolloStore {
/// to assist in de-duping cache hits for watchers.
/// - callbackQueue: The queue to call the completion block on. Defaults to `DispatchQueue.main`.
/// - completion: [optional] A completion block to be called after records are merged into the cache.
public func publish(records: RecordSet, identifier: UUID? = nil, callbackQueue: DispatchQueue = .main, completion: ((Result<Void, Swift.Error>) -> Void)? = nil) {
public func publish(records: RecordSet, identifier: UUID? = nil, callbackQueue: DispatchQueue = .main, completion: ((Result<Void, any Swift.Error>) -> Void)? = nil) {
queue.async(flags: .barrier) {
do {
let changedKeys = try self.cache.merge(records: records)
Expand All @@ -90,7 +90,7 @@ public class ApolloStore {
/// - Parameters:
/// - subscriber: A subscriber to receive content change notificatons. To avoid a retain cycle,
/// ensure you call `unsubscribe` on this subscriber before it goes out of scope.
public func subscribe(_ subscriber: ApolloStoreSubscriber) {
public func subscribe(_ subscriber: any ApolloStoreSubscriber) {
queue.async(flags: .barrier) {
self.subscribers.append(subscriber)
}
Expand All @@ -101,7 +101,7 @@ public class ApolloStore {
/// - Parameters:
/// - subscriber: A subscribe that has previously been added via `subscribe`. To avoid retain cycles,
/// call `unsubscribe` on all active subscribers before they go out of scope.
public func unsubscribe(_ subscriber: ApolloStoreSubscriber) {
public func unsubscribe(_ subscriber: any ApolloStoreSubscriber) {
queue.async(flags: .barrier) {
self.subscribers = self.subscribers.filter({ $0 !== subscriber })
}
Expand All @@ -116,7 +116,7 @@ public class ApolloStore {
public func withinReadTransaction<T>(
_ body: @escaping (ReadTransaction) throws -> T,
callbackQueue: DispatchQueue? = nil,
completion: ((Result<T, Swift.Error>) -> Void)? = nil
completion: ((Result<T, any Swift.Error>) -> Void)? = nil
) {
self.queue.async {
do {
Expand Down Expand Up @@ -146,7 +146,7 @@ public class ApolloStore {
public func withinReadWriteTransaction<T>(
_ body: @escaping (ReadWriteTransaction) throws -> T,
callbackQueue: DispatchQueue? = nil,
completion: ((Result<T, Swift.Error>) -> Void)? = nil
completion: ((Result<T, any Swift.Error>) -> Void)? = nil
) {
self.queue.async(flags: .barrier) {
do {
Expand Down Expand Up @@ -201,7 +201,7 @@ public class ApolloStore {
}

public class ReadTransaction {
fileprivate let cache: NormalizedCache
fileprivate let cache: any NormalizedCache

fileprivate lazy var loader: DataLoader<CacheKey, Record> = DataLoader(self.cache.loadRecords)
fileprivate lazy var executor = GraphQLExecutor(
Expand Down
4 changes: 2 additions & 2 deletions Sources/Apollo/AutomaticPersistedQueryInterceptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public struct AutomaticPersistedQueryInterceptor: ApolloInterceptor {
public init() {}

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

guard let jsonRequest = request as? JSONRequest,
jsonRequest.autoPersistQueries else {
Expand Down
8 changes: 4 additions & 4 deletions Sources/Apollo/CacheReadInterceptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public struct CacheReadInterceptor: ApolloInterceptor {
}

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

switch Operation.operationType {
case .mutation,
Expand Down Expand Up @@ -115,8 +115,8 @@ public struct CacheReadInterceptor: ApolloInterceptor {

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

self.store.load(request.operation) { loadResult in
guard !chain.isCancelled else {
Expand Down
Loading

0 comments on commit f957243

Please sign in to comment.