【问题标题】:How to pass AWS AppSync custom request header in iOS client?如何在 iOS 客户端中传递 AWS AppSync 自定义请求标头?
【发布时间】:2019-01-26 16:58:58
【问题描述】:
【问题讨论】:
标签:
ios
swift
amazon-web-services
graphql
aws-appsync
【解决方案1】:
我刚刚找到了一种在 iOS 客户端中传递额外 AWS AppSync 请求标头的方法 :)
这是 AppSyncManager 的示例类
final class AppSyncManager {
static func instance() -> AWSAppSyncClient {
let tmpURL = URL(fileURLWithPath: NSTemporaryDirectory())
let databaseURL = tmpURL.appendingPathComponent(databasName)
let urlSessionConfiguration = URLSessionConfiguration.default
// Our request header => In resolve mapping: $context.request.headers.author
urlSessionConfiguration.httpAdditionalHeaders = ["author": CognitoUserPoolManager.instance.author]
let appSyncConfig = try! AWSAppSyncClientConfiguration(url: endPointURL,
serviceRegion: region,
userPoolsAuthProvider: CognitoAuthProvider(),
urlSessionConfiguration: urlSessionConfiguration,
databaseURL: databaseURL)
let appSyncClient = try! AWSAppSyncClient(appSyncConfig: appSyncConfig)
appSyncClient.apolloClient?.cacheKeyForObject = { $0["id"] }
return appSyncClient
}
}