Skip to content

Commit 1a7c84c

Browse files
authored
Merge pull request #10 from futuredapp/feature/Update-to-Apollo-2.0.4
Update to Apollo 2.0.4
2 parents f594464 + 378811a commit 1a7c84c

21 files changed

Lines changed: 422 additions & 664 deletions

‎Package.resolved‎

Lines changed: 2 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Package.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ let package = Package(
2020
dependencies: [
2121
.package(
2222
url: "https://github.com/apollographql/apollo-ios.git",
23-
exact: "1.17.0" // Do not forget to download related to this version Apollo CLI and include it with package
23+
exact: "2.0.4"
2424
)
2525
],
2626
targets: [

‎README.md‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Developed to simplify [Futured](https://www.futured.app) in-house development of
77

88
- iOS 16.0+ / macOS 13.0+
99
- Swift 5.9+
10-
- Apollo iOS 1.17.0
10+
- Apollo iOS 2.0.4
1111

1212
## Limitations
1313

@@ -51,7 +51,7 @@ Copy and paste json configuration to the newly created file:
5151
"schemaTypes" : {
5252
"path" : "./",
5353
"moduleType" : {
54-
"swiftPackageManager": {}
54+
"swiftPackage": {}
5555
}
5656
},
5757
"operations" : {
@@ -74,7 +74,7 @@ Add `Queries` and `Mutations` folders to `GraphQLGenerated` folder.
7474
#### 5. Define Your first GraphQL Query Or Mutation
7575
Add your first Query or Mutation and save it with `.graphql` extension to `Queries` or `Mutations` folders.
7676

77-
#### 6. Add Xcode Biuld Phase Script
77+
#### 6. Add Xcode Build Phase Script
7878
At your main app's target add a new build phase named `Generate GraphQL Operations`.
7979
Move your newly created build phase above the `Compile Sources` phase.
8080
Add script:
@@ -120,11 +120,12 @@ let mutation = MyExampleMutation()
120120
import GraphQLAPIKit
121121
import GraphQLGenerated
122122

123-
let apiAdapter = GraphQLAPIAdapter(
123+
let configuration = GraphQLAPIConfiguration(
124124
url: URL(string: "https://api.example.com/graphql")!
125125
)
126-
let queryResult = await apiAdapter.fetch(query: query)
127-
let mutationResult = await apiAdapter.perform(mutation: mutation)
126+
let apiAdapter = GraphQLAPIAdapter(configuration: configuration)
127+
let queryResult = try await apiAdapter.fetch(query: query)
128+
let mutationResult = try await apiAdapter.perform(mutation: mutation)
128129
```
129130

130131
## Contributors

‎Resources/apollo-ios-cli‎

-491 KB
Binary file not shown.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import Foundation
2+
3+
/// Configuration for initializing a GraphQL API adapter.
4+
///
5+
/// Use this struct to configure the GraphQL client with endpoint URL,
6+
/// session configuration, default headers, and network observers.
7+
public struct GraphQLAPIConfiguration: Sendable {
8+
/// The GraphQL endpoint URL.
9+
public let url: URL
10+
11+
/// URL session configuration. Defaults to `.default`.
12+
public let urlSessionConfiguration: URLSessionConfiguration
13+
14+
/// Headers to include in every request.
15+
public let defaultHeaders: [String: String]
16+
17+
/// Network observers for monitoring requests (logging, analytics, etc.).
18+
public let networkObservers: [any GraphQLNetworkObserver]
19+
20+
/// Creates a new GraphQL API configuration.
21+
///
22+
/// - Parameters:
23+
/// - url: The GraphQL endpoint URL.
24+
/// - urlSessionConfiguration: URL session configuration. Defaults to `.default`.
25+
/// - defaultHeaders: Headers to include in every request. Defaults to empty.
26+
/// - networkObservers: Network observers for monitoring requests. Defaults to empty.
27+
public init(
28+
url: URL,
29+
urlSessionConfiguration: URLSessionConfiguration = .default,
30+
defaultHeaders: [String: String] = [:],
31+
networkObservers: [any GraphQLNetworkObserver] = []
32+
) {
33+
self.url = url
34+
self.urlSessionConfiguration = urlSessionConfiguration
35+
self.defaultHeaders = defaultHeaders
36+
self.networkObservers = networkObservers
37+
}
38+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import Foundation
2+
3+
/// Base protocol for GraphQL operation configurations.
4+
///
5+
/// Defines common options shared across all GraphQL operations (queries, mutations, subscriptions).
6+
public protocol GraphQLOperationConfiguration: Sendable {
7+
/// Additional headers to add to the request.
8+
var headers: RequestHeaders? { get }
9+
}
10+
11+
/// Configuration for GraphQL queries and mutations.
12+
///
13+
/// Use this struct to customize request-specific options like additional headers.
14+
public struct GraphQLRequestConfiguration: GraphQLOperationConfiguration {
15+
/// Additional headers to add to the request.
16+
public let headers: RequestHeaders?
17+
18+
/// Creates a new request configuration.
19+
///
20+
/// - Parameter headers: Additional headers to add to the request. Defaults to `nil`.
21+
public init(headers: RequestHeaders? = nil) {
22+
self.headers = headers
23+
}
24+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Apollo
22

3-
struct ApolloError: Error {
3+
struct ApolloError: Error, Sendable {
44
let errors: [Apollo.GraphQLError]
55
}

‎Sources/GraphQLAPIKit/Errors/GraphQLAPIAdapterError.swift‎

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import Apollo
22
import Foundation
33

4-
public enum GraphQLAPIAdapterError: LocalizedError {
5-
/// Network error received by Apollo from `URLSessionTaskDelegate`
4+
public enum GraphQLAPIAdapterError: LocalizedError, Sendable {
5+
/// Network error with HTTP status code
66
case network(code: Int, error: Error)
77

88
/// The app is offline or doesn't have access to the network.
99
case connection(Error)
1010

11-
/// Unhandled network error received from `Apollo.URLSessionClient`
11+
/// Unhandled error
1212
case unhandled(Error)
1313

1414
/// Request was cancelled
@@ -23,15 +23,31 @@ public enum GraphQLAPIAdapterError: LocalizedError {
2323
self = error
2424
} else if let error = error as? ApolloError {
2525
self = .graphQl(error.errors.map(GraphQLError.init))
26-
} else if let error = error as? URLSessionClient.URLSessionClientError,
27-
case let URLSessionClient.URLSessionClientError.networkError(_, response, underlyingError) = error {
28-
if let response = response {
29-
self = .network(code: response.statusCode, error: underlyingError)
30-
} else {
31-
self = .connection(underlyingError)
26+
} else if error is CancellationError {
27+
self = .cancelled
28+
} else if let urlError = error as? URLError {
29+
switch urlError.code {
30+
case .cancelled:
31+
self = .cancelled
32+
case .notConnectedToInternet, .networkConnectionLost, .dataNotAllowed:
33+
self = .connection(urlError)
34+
default:
35+
self = .unhandled(urlError)
3236
}
3337
} else {
34-
self = .unhandled(error)
38+
let nsError = error as NSError
39+
if nsError.domain == NSURLErrorDomain {
40+
if nsError.code == NSURLErrorCancelled {
41+
self = .cancelled
42+
} else if nsError.code == NSURLErrorNotConnectedToInternet ||
43+
nsError.code == NSURLErrorNetworkConnectionLost {
44+
self = .connection(error)
45+
} else {
46+
self = .unhandled(error)
47+
}
48+
} else {
49+
self = .unhandled(error)
50+
}
3551
}
3652
}
3753

‎Sources/GraphQLAPIKit/Errors/GraphQLAPIError.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Apollo
22
import Foundation
33

4-
public struct GraphQLError: LocalizedError {
4+
public struct GraphQLError: LocalizedError, Sendable {
55
public let message: String
66
public let code: String?
77

‎Sources/GraphQLAPIKit/Extensions/GraphQLAPIAdapter+Extensions.swift‎

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)