Skip to content

Commit 0870750

Browse files
committed
Adapt to new interface
1 parent 9037332 commit 0870750

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

GitHub-GraphQL-API-Example-iOS/API.swift

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public final class SearchRepositoriesQuery: GraphQLQuery {
1616
node {
1717
__typename
1818
... on Repository {
19+
__typename
1920
...RepositoryDetails
2021
}
2122
}
@@ -220,6 +221,7 @@ public final class SearchRepositoriesQuery: GraphQLQuery {
220221

221222
public static var selections: [GraphQLSelection] {
222223
return [
224+
GraphQLField("__typename", type: .nonNull(.scalar(String.self))),
223225
GraphQLField("__typename", type: .nonNull(.scalar(String.self))),
224226
GraphQLFragmentSpread(RepositoryDetails.self),
225227
]

GitHub-GraphQL-API-Example-iOS/RepositoriesViewController.swift

+16-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Apollo
33

44
private let token = "YOUR_TOKEN"
55

6-
class TokenAddingInterceptor: ApolloInterceptor {
6+
final class TokenAddingInterceptor: ApolloInterceptor {
77
func interceptAsync<Operation: GraphQLOperation>(
88
chain: RequestChain,
99
request: HTTPRequest<Operation>,
@@ -14,11 +14,21 @@ class TokenAddingInterceptor: ApolloInterceptor {
1414
}
1515
}
1616

17-
class NetworkInterceptorProvider: LegacyInterceptorProvider {
18-
override func interceptors<Operation: GraphQLOperation>(for operation: Operation) -> [ApolloInterceptor] {
19-
var interceptors = super.interceptors(for: operation)
20-
interceptors.insert(TokenAddingInterceptor(), at: 0)
21-
return interceptors
17+
final class NetworkInterceptorProvider: InterceptorProvider {
18+
private let client: URLSessionClient
19+
private let store: ApolloStore
20+
21+
init(client: URLSessionClient, store: ApolloStore) {
22+
self.client = client
23+
self.store = store
24+
}
25+
26+
func interceptors<Operation>(for operation: Operation) -> [ApolloInterceptor] where Operation : GraphQLOperation {
27+
[
28+
TokenAddingInterceptor(),
29+
NetworkFetchInterceptor(client: self.client),
30+
JSONResponseParsingInterceptor(cacheKeyForObject: self.store.cacheKeyForObject),
31+
]
2232
}
2333
}
2434

0 commit comments

Comments
 (0)