Skip to content

Commit

Permalink
Compatibility fixes for 1.9.1 (apollographql/apollo-ios-dev#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyMDev authored and gh-action-runner committed Mar 8, 2024
1 parent 569f814 commit 9e65157
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
57 changes: 57 additions & 0 deletions Sources/Apollo/ApolloClientProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,60 @@ public protocol ApolloClientProtocol: AnyObject {
queue: DispatchQueue,
resultHandler: @escaping GraphQLResultHandler<Subscription.Data>) -> Cancellable
}

// MARK: - Backwards Compatibilty Extension

public extension ApolloClientProtocol {

/// Fetches a query from the server or from the local cache, depending on the current contents of the cache and the specified cache policy.
///
/// - Parameters:
/// - query: The query to fetch.
/// - cachePolicy: A cache policy that specifies when results should be fetched from the server and when data should be loaded from the local cache.
/// - queue: A dispatch queue on which the result handler will be called. Should default to the main queue.
/// - context: [optional] A context that is being passed through the request chain. Should default to `nil`.
/// - resultHandler: [optional] A closure that is called when query results are available or when an error occurs.
/// - Returns: An object that can be used to cancel an in progress fetch.
func fetch<Query: GraphQLQuery>(
query: Query,
cachePolicy: CachePolicy,
context: RequestContext?,
queue: DispatchQueue,
resultHandler: GraphQLResultHandler<Query.Data>?
) -> Cancellable {
self.fetch(
query: query,
cachePolicy: cachePolicy,
contextIdentifier: nil,
context: context,
queue: queue,
resultHandler: resultHandler
)
}

/// Performs a mutation by sending it to the server.
///
/// - Parameters:
/// - mutation: The mutation to perform.
/// - publishResultToStore: If `true`, this will publish the result returned from the operation to the cache store. Default is `true`.
/// - context: [optional] A context that is being passed through the request chain. Should default to `nil`.
/// - queue: A dispatch queue on which the result handler will be called. Should default to the main queue.
/// - 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 mutation.
func perform<Mutation: GraphQLMutation>(
mutation: Mutation,
publishResultToStore: Bool,
context: RequestContext?,
queue: DispatchQueue,
resultHandler: GraphQLResultHandler<Mutation.Data>?
) -> Cancellable {
self.perform(
mutation: mutation,
publishResultToStore: publishResultToStore,
contextIdentifier: nil,
context: context,
queue: queue,
resultHandler: resultHandler
)
}
}
14 changes: 13 additions & 1 deletion Sources/Apollo/URLSessionClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,19 @@ open class URLSessionClient: NSObject, URLSessionDelegate, URLSessionTaskDelegat

return task
}


@discardableResult
open func sendRequest(_ request: URLRequest,
rawTaskCompletionHandler: RawCompletion? = nil,
completion: @escaping Completion) -> URLSessionTask {
sendRequest(
request,
taskDescription: nil,
rawTaskCompletionHandler: nil,
completion: completion
)
}

/// Cancels a given task and clears out its underlying data.
///
/// NOTE: You will not receive any kind of "This was cancelled" error when this is called.
Expand Down

0 comments on commit 9e65157

Please sign in to comment.