How to pass AWS AppSync custom request header in i

2019-08-19 02:32发布

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

2条回答
Viruses.
2楼-- · 2019-08-19 02:58

In the latest aws-mobile-appsync-sdk-ios SDK 2.6.22, Issue is being fixed.

查看更多
一纸荒年 Trace。
3楼-- · 2019-08-19 03:19

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
    }

}
查看更多
登录 后发表回答