【问题标题】:How to pass AWS AppSync custom request header in iOS client?如何在 iOS 客户端中传递 AWS AppSync 自定义请求标头?
【发布时间】:2019-01-26 16:58:58
【问题描述】:

AWS AppSync 支持从客户端传递自定义标头并使用 $context.request.headers 在您的 GraphQL 解析器中访问它们。
我想知道我该怎么做在 iOS 客户端中?
谢谢 :)
https://docs.aws.amazon.com/appsync/latest/devguide/resolver-context-reference.html

【问题讨论】:

    标签: 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
        }
    
    }
    

    【讨论】:

    • 如何在 Android 中实现?
    【解决方案2】:

    在最新的aws-mobile-appsync-sdk-ios SDK 2.6.22 中,问题正在修复中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-08
      • 2021-11-02
      • 1970-01-01
      • 1970-01-01
      • 2021-03-21
      • 2018-08-06
      • 2018-07-11
      • 1970-01-01
      相关资源
      最近更新 更多