Created
May 30, 2019 22:51
-
-
Save dmennis/b7b7735da0c138b0eb352a7cbc053ad4 to your computer and use it in GitHub Desktop.
iOS AppSync Multi Auth - API_KEY
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// WITH multi-auth | |
func initializeAppSync_API_Key() { | |
do { | |
// Reference the API_KEY auth mode setting in awsconfiguration.json | |
let serviceConfigAPI_Key = try AWSAppSyncServiceConfig(forKey: "recipedemo_API_KEY") | |
// useClientDatabasePrefix: true is telling the AppSync client to look for 'ClientDatabasePrefix' in awsconfiguration.json | |
// why the cacheConfig? AppSync client uses a unique cache database for each auth type | |
let cacheConfig = try AWSAppSyncCacheConfiguration(useClientDatabasePrefix: true, | |
appSyncServiceConfig: serviceConfigAPI_Key) | |
// Initialize the AWS AppSync configuration to reference the "recipedemo_API_KEY" auth mode in awsconfiguration.json | |
let appSyncConfig = try AWSAppSyncClientConfiguration(appSyncServiceConfig: serviceConfigAPI_Key, cacheConfiguration: cacheConfig) | |
// Initialize the AWS AppSync client | |
appSyncClient = try AWSAppSyncClient(appSyncConfig: appSyncConfig) | |
} catch { | |
print("Error initializing appsync client. \(error)") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment