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 2e66dc3
Show file tree
Hide file tree
Showing 4 changed files with 96 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1520"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "211034E72BD2E02A006AC186"
BuildableName = "AuthGen2IntegrationTests.xctest"
BlueprintName = "AuthGen2IntegrationTests"
ReferencedContainer = "container:AuthHostApp.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

0 comments on commit 2e66dc3

Please sign in to comment.