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
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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
}
}
回答2:
In the latest aws-mobile-appsync-sdk-ios SDK 2.6.22
, Issue is being fixed.