forked from aws-amplify/aws-appsync-apollo-extensions-swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDefaultPrependInterceptorProvider.swift
37 lines (28 loc) · 1.06 KB
/
DefaultPrependInterceptorProvider.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
import Apollo
import ApolloAPI
import Foundation
public class DefaultPrependInterceptorProvider: DefaultInterceptorProvider {
let interceptor: ApolloInterceptor
public init(interceptor: ApolloInterceptor,
client: URLSessionClient = URLSessionClient(),
shouldInvalidateClientOnDeinit: Bool = true,
store: ApolloStore)
{
self.interceptor = interceptor
super.init(client: client, shouldInvalidateClientOnDeinit: shouldInvalidateClientOnDeinit, store: store)
}
override public func interceptors<Operation>(for operation: Operation) -> [ApolloInterceptor] where Operation: GraphQLOperation {
var interceptors = super.interceptors(for: operation)
addInterceptorToBeginning(&interceptors)
return interceptors
}
func addInterceptorToBeginning(_ interceptors: inout [any ApolloInterceptor]) {
interceptors.insert(interceptor, at: 0)
}
}