From e5ced1e0ab6e9def6f789633605291bb734b0ebd Mon Sep 17 00:00:00 2001 From: Matt Jarjoura Date: Sat, 15 Mar 2025 15:42:08 -0700 Subject: [PATCH] Update imports to support building on Linux --- Sources/Apollo/Bundle+Helpers.swift | 2 ++ Sources/Apollo/Cancellable.swift | 3 +++ Sources/Apollo/HTTPRequest.swift | 3 +++ Sources/Apollo/HTTPResponse.swift | 3 +++ Sources/Apollo/HTTPURLResponse+Helpers.swift | 3 +++ Sources/Apollo/JSONRequest.swift | 3 +++ Sources/Apollo/NetworkFetchInterceptor.swift | 3 +++ Sources/Apollo/NetworkTransport.swift | 5 +++++ Sources/Apollo/ResponseCodeInterceptor.swift | 3 +++ Sources/Apollo/TaskData.swift | 3 +++ Sources/Apollo/URLSessionClient.swift | 3 +++ Sources/Apollo/UploadRequest.swift | 3 +++ 12 files changed, 37 insertions(+) diff --git a/Sources/Apollo/Bundle+Helpers.swift b/Sources/Apollo/Bundle+Helpers.swift index c8d86f8b97..bcc46d45df 100644 --- a/Sources/Apollo/Bundle+Helpers.swift +++ b/Sources/Apollo/Bundle+Helpers.swift @@ -1,3 +1,4 @@ +#if !os(Linux) import Foundation extension Bundle { @@ -25,3 +26,4 @@ extension Bundle { return self.bundleValue(forKey: "CFBundleShortVersionString") } } +#endif // !os(Linux) diff --git a/Sources/Apollo/Cancellable.swift b/Sources/Apollo/Cancellable.swift index 73b502b7d7..ec37105583 100644 --- a/Sources/Apollo/Cancellable.swift +++ b/Sources/Apollo/Cancellable.swift @@ -1,4 +1,7 @@ import Foundation +#if canImport(FoundationNetworking) +import FoundationNetworking +#endif /// An object that can be used to cancel an in progress action. public protocol Cancellable: AnyObject { diff --git a/Sources/Apollo/HTTPRequest.swift b/Sources/Apollo/HTTPRequest.swift index 1a56a468eb..1ed159b48b 100644 --- a/Sources/Apollo/HTTPRequest.swift +++ b/Sources/Apollo/HTTPRequest.swift @@ -2,6 +2,9 @@ import Foundation #if !COCOAPODS import ApolloAPI #endif +#if canImport(FoundationNetworking) +import FoundationNetworking +#endif /// Encapsulation of all information about a request before it hits the network open class HTTPRequest: Hashable { diff --git a/Sources/Apollo/HTTPResponse.swift b/Sources/Apollo/HTTPResponse.swift index 2b2cb27f7a..b148c60f9b 100644 --- a/Sources/Apollo/HTTPResponse.swift +++ b/Sources/Apollo/HTTPResponse.swift @@ -2,6 +2,9 @@ import Foundation #if !COCOAPODS import ApolloAPI #endif +#if canImport(FoundationNetworking) +import FoundationNetworking +#endif /// Data about a response received by an HTTP request. public class HTTPResponse { diff --git a/Sources/Apollo/HTTPURLResponse+Helpers.swift b/Sources/Apollo/HTTPURLResponse+Helpers.swift index 05f298ad45..7739f724da 100644 --- a/Sources/Apollo/HTTPURLResponse+Helpers.swift +++ b/Sources/Apollo/HTTPURLResponse+Helpers.swift @@ -1,4 +1,7 @@ import Foundation +#if canImport(FoundationNetworking) +import FoundationNetworking +#endif // MARK: Status extensions extension HTTPURLResponse { diff --git a/Sources/Apollo/JSONRequest.swift b/Sources/Apollo/JSONRequest.swift index 4e6eea6469..983e0e5c51 100644 --- a/Sources/Apollo/JSONRequest.swift +++ b/Sources/Apollo/JSONRequest.swift @@ -2,6 +2,9 @@ import Foundation #if !COCOAPODS import ApolloAPI #endif +#if canImport(FoundationNetworking) +import FoundationNetworking +#endif /// A request which sends JSON related to a GraphQL operation. open class JSONRequest: HTTPRequest { diff --git a/Sources/Apollo/NetworkFetchInterceptor.swift b/Sources/Apollo/NetworkFetchInterceptor.swift index 4b7636b3d1..2087a10361 100644 --- a/Sources/Apollo/NetworkFetchInterceptor.swift +++ b/Sources/Apollo/NetworkFetchInterceptor.swift @@ -2,6 +2,9 @@ import Foundation #if !COCOAPODS import ApolloAPI #endif +#if canImport(FoundationNetworking) +import FoundationNetworking +#endif /// An interceptor which actually fetches data from the network. public class NetworkFetchInterceptor: ApolloInterceptor, Cancellable { diff --git a/Sources/Apollo/NetworkTransport.swift b/Sources/Apollo/NetworkTransport.swift index e594f9462f..0686702e93 100644 --- a/Sources/Apollo/NetworkTransport.swift +++ b/Sources/Apollo/NetworkTransport.swift @@ -2,6 +2,9 @@ import Foundation #if !COCOAPODS import ApolloAPI #endif +#if canImport(FoundationNetworking) +import FoundationNetworking +#endif /// A network transport is responsible for sending GraphQL operations to a server. public protocol NetworkTransport: AnyObject { @@ -60,6 +63,7 @@ public extension NetworkTransport { /// The default client version to use when setting up the `clientVersion` property. static var defaultClientVersion: String { var version = String() +#if !os(Linux) if let shortVersion = Bundle.main.shortVersion { version.append(shortVersion) } @@ -71,6 +75,7 @@ public extension NetworkTransport { version.append("-\(buildNumber)") } } +#endif // !os(Linux) if version.isEmpty { version = "(unknown)" diff --git a/Sources/Apollo/ResponseCodeInterceptor.swift b/Sources/Apollo/ResponseCodeInterceptor.swift index b4d1837c24..49ad286dc7 100644 --- a/Sources/Apollo/ResponseCodeInterceptor.swift +++ b/Sources/Apollo/ResponseCodeInterceptor.swift @@ -2,6 +2,9 @@ import Foundation #if !COCOAPODS import ApolloAPI #endif +#if canImport(FoundationNetworking) +import FoundationNetworking +#endif /// An interceptor to check the response code returned with a request. public struct ResponseCodeInterceptor: ApolloInterceptor { diff --git a/Sources/Apollo/TaskData.swift b/Sources/Apollo/TaskData.swift index 2cae3c1594..8b1020df71 100644 --- a/Sources/Apollo/TaskData.swift +++ b/Sources/Apollo/TaskData.swift @@ -1,4 +1,7 @@ import Foundation +#if canImport(FoundationNetworking) +import FoundationNetworking +#endif /// A wrapper for data about a particular task handled by `URLSessionClient` public class TaskData { diff --git a/Sources/Apollo/URLSessionClient.swift b/Sources/Apollo/URLSessionClient.swift index 3fe94c79cc..4934b977f8 100644 --- a/Sources/Apollo/URLSessionClient.swift +++ b/Sources/Apollo/URLSessionClient.swift @@ -1,4 +1,7 @@ import Foundation +#if canImport(FoundationNetworking) +import FoundationNetworking +#endif /// A class to handle URL Session calls that will support background execution, /// but still (mostly) use callbacks for its primary method of communication. diff --git a/Sources/Apollo/UploadRequest.swift b/Sources/Apollo/UploadRequest.swift index 761a375fcd..09c34b1ff8 100644 --- a/Sources/Apollo/UploadRequest.swift +++ b/Sources/Apollo/UploadRequest.swift @@ -2,6 +2,9 @@ import Foundation #if !COCOAPODS import ApolloAPI #endif +#if canImport(FoundationNetworking) +import FoundationNetworking +#endif /// A request class allowing for a multipart-upload request. open class UploadRequest: HTTPRequest {