Skip to content

Commit

Permalink
feat(api): runtime authtype support
Browse files Browse the repository at this point in the history
  • Loading branch information
lawmicha committed Apr 23, 2024
1 parent adf5a2e commit 47cbce3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

import Foundation
import AWSPluginsCore

public struct AppSyncGraphQLRequestOptions {

/// authorization type
public let authType: AWSAuthorizationType?

public init(authType: AWSAuthorizationType? = nil) {
self.authType = authType
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ final public class AWSGraphQLOperation<R: Decodable>: GraphQLOperation<R> {
withConfig: endpointConfig,
authType: authType
))
} else if let pluginOptions = request.options.pluginOptions as? AppSyncGraphQLRequestOptions,
let authType = pluginOptions.authType {
return .success(try pluginConfig.interceptorsForEndpoint(
withConfig: endpointConfig,
authType: authType
))
} else {
return .success(pluginConfig.interceptorsForEndpoint(withConfig: endpointConfig))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,20 @@ public class AWSGraphQLSubscriptionTaskRunner<R: Decodable>: InternalTaskRunner,
return
}

let pluginOptions = request.options.pluginOptions as? AWSAPIPluginDataStoreOptions
// Retrieve the subscription connection
let authType: AWSAuthorizationType?
if let pluginOptions = request.options.pluginOptions as? AWSAPIPluginDataStoreOptions {
authType = pluginOptions.authType
} else if let pluginOptions = request.options.pluginOptions as? AppSyncGraphQLRequestOptions {
authType = pluginOptions.authType
} else {
authType = nil
}
do {
self.appSyncClient = try await appSyncClientFactory.getAppSyncRealTimeClient(
for: endpointConfig,
endpoint: endpointConfig.baseURL,
authService: authService,
authType: pluginOptions?.authType,
authType: authType,
apiAuthProviderFactory: apiAuthProviderFactory
)

Expand Down Expand Up @@ -262,14 +268,21 @@ final public class AWSGraphQLSubscriptionOperation<R: Decodable>: GraphQLSubscri
return
}

let pluginOptions = request.options.pluginOptions as? AWSAPIPluginDataStoreOptions
let authType: AWSAuthorizationType?
if let pluginOptions = request.options.pluginOptions as? AWSAPIPluginDataStoreOptions {
authType = pluginOptions.authType
} else if let pluginOptions = request.options.pluginOptions as? AppSyncGraphQLRequestOptions {
authType = pluginOptions.authType
} else {
authType = nil
}
Task {
do {
appSyncRealTimeClient = try await appSyncRealTimeClientFactory.getAppSyncRealTimeClient(
for: endpointConfig,
endpoint: endpointConfig.baseURL,
authService: authService,
authType: pluginOptions?.authType,
authType: authType,
apiAuthProviderFactory: apiAuthProviderFactory
)

Expand Down

0 comments on commit 47cbce3

Please sign in to comment.