本文介绍了如何在iOS客户端中传递AWS AppSync自定义请求标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
AWS AppSync支持从客户端传递自定义标头,并使用 $ context.request.headers 在GraphQL解析器中访问它们.在iOS客户端中?
谢谢:)
https://docs.aws.amazon .com/appsync/latest/devguide/resolver-context-reference.html
AWS AppSync supports passing custom headers from clients and accessing them in your GraphQL resolvers using $context.request.headers.
I wonder how can I do that in iOS client ?
Thanks :)
https://docs.aws.amazon.com/appsync/latest/devguide/resolver-context-reference.html
推荐答案
我刚刚找到了一种在iOS客户端中传递其他AWS AppSync请求标头的方法:)
这是AppSyncManager
I've just found a way to pass additional AWS AppSync Request Header in iOS Client :)
Here is a sample class of 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
}
}
这篇关于如何在iOS客户端中传递AWS AppSync自定义请求标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!