UpdateGraphqlApi Swift Example
func chilkatTest() {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let rest = CkoRest()
var success: Bool
let authAws = CkoAuthAws()
authAws.AccessKey = "AWS_ACCESS_KEY"
authAws.SecretKey = "AWS_SECRET_KEY"
// Don't forget to change the region to your particular region. (Also make the same change in the call to Connect below.)
authAws.Region = "us-west-2"
authAws.ServiceName = "appsync"
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
rest.SetAuthAws(authAws)
// URL: https://appsync.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = rest.Connect("appsync.us-west-2.amazonaws.com", port: 443, tls: true, autoReconnect: true)
if success != true {
print("ConnectFailReason: \(rest.ConnectFailReason.intValue)")
print("\(rest.LastErrorText)")
return
}
// The following code creates the JSON request body.
// The JSON created by this code is shown below.
// Use this online tool to generate code from sample JSON:
// Generate Code to Create JSON
let json = CkoJsonObject()
json.UpdateString("additionalAuthenticationProviders[0].authenticationType", value: "string")
json.UpdateInt("additionalAuthenticationProviders[0].lambdaAuthorizerConfig.authorizerResultTtlInSeconds", value: 123)
json.UpdateString("additionalAuthenticationProviders[0].lambdaAuthorizerConfig.authorizerUri", value: "string")
json.UpdateString("additionalAuthenticationProviders[0].lambdaAuthorizerConfig.identityValidationExpression", value: "string")
json.UpdateInt("additionalAuthenticationProviders[0].openIDConnectConfig.authTTL", value: 123)
json.UpdateString("additionalAuthenticationProviders[0].openIDConnectConfig.clientId", value: "string")
json.UpdateInt("additionalAuthenticationProviders[0].openIDConnectConfig.iatTTL", value: 123)
json.UpdateString("additionalAuthenticationProviders[0].openIDConnectConfig.issuer", value: "string")
json.UpdateString("additionalAuthenticationProviders[0].userPoolConfig.appIdClientRegex", value: "string")
json.UpdateString("additionalAuthenticationProviders[0].userPoolConfig.awsRegion", value: "string")
json.UpdateString("additionalAuthenticationProviders[0].userPoolConfig.userPoolId", value: "string")
json.UpdateString("authenticationType", value: "string")
json.UpdateInt("lambdaAuthorizerConfig.authorizerResultTtlInSeconds", value: 123)
json.UpdateString("lambdaAuthorizerConfig.authorizerUri", value: "string")
json.UpdateString("lambdaAuthorizerConfig.identityValidationExpression", value: "string")
json.UpdateString("logConfig.cloudWatchLogsRoleArn", value: "string")
json.UpdateInt("logConfig.excludeVerboseContent", value: 123)
json.UpdateString("logConfig.fieldLogLevel", value: "string")
json.UpdateString("name", value: "string")
json.UpdateInt("openIDConnectConfig.authTTL", value: 123)
json.UpdateString("openIDConnectConfig.clientId", value: "string")
json.UpdateInt("openIDConnectConfig.iatTTL", value: 123)
json.UpdateString("openIDConnectConfig.issuer", value: "string")
json.UpdateString("userPoolConfig.appIdClientRegex", value: "string")
json.UpdateString("userPoolConfig.awsRegion", value: "string")
json.UpdateString("userPoolConfig.defaultAction", value: "string")
json.UpdateString("userPoolConfig.userPoolId", value: "string")
json.UpdateInt("xrayEnabled", value: 123)
// The JSON request body created by the above code:
// {
// "additionalAuthenticationProviders": [
// {
// "authenticationType": "string",
// "lambdaAuthorizerConfig": {
// "authorizerResultTtlInSeconds": number,
// "authorizerUri": "string",
// "identityValidationExpression": "string"
// },
// "openIDConnectConfig": {
// "authTTL": number,
// "clientId": "string",
// "iatTTL": number,
// "issuer": "string"
// },
// "userPoolConfig": {
// "appIdClientRegex": "string",
// "awsRegion": "string",
// "userPoolId": "string"
// }
// }
// ],
// "authenticationType": "string",
// "lambdaAuthorizerConfig": {
// "authorizerResultTtlInSeconds": number,
// "authorizerUri": "string",
// "identityValidationExpression": "string"
// },
// "logConfig": {
// "cloudWatchLogsRoleArn": "string",
// "excludeVerboseContent": boolean,
// "fieldLogLevel": "string"
// },
// "name": "string",
// "openIDConnectConfig": {
// "authTTL": number,
// "clientId": "string",
// "iatTTL": number,
// "issuer": "string"
// },
// "userPoolConfig": {
// "appIdClientRegex": "string",
// "awsRegion": "string",
// "defaultAction": "string",
// "userPoolId": "string"
// },
// "xrayEnabled": boolean
// }
rest.AddHeader("Content-Type", value: "application/x-amz-json-1.1")
rest.AddHeader("X-Amz-Target", value: "UpdateGraphqlApi")
let sbRequestBody = CkoStringBuilder()
json.EmitSb(sbRequestBody)
let sbResponseBody = CkoStringBuilder()
success = rest.FullRequestSb("POST", uriPath: "/v1/apis/{apiId}", requestBody: sbRequestBody, responseBody: sbResponseBody)
if success != true {
print("\(rest.LastErrorText)")
return
}
var respStatusCode: Int = rest.ResponseStatusCode.intValue
print("response status code = \(respStatusCode)")
if respStatusCode != 200 {
print("Response Header:")
print("\(rest.ResponseHeader)")
print("Response Body:")
print("\(sbResponseBody.GetAsString())")
return
}
let jResp = CkoJsonObject()
jResp.LoadSb(sbResponseBody)
// The following code parses the JSON response.
// A sample JSON response is shown below the sample code.
// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
var authenticationType: String?
var lambdaAuthorizerConfigAuthorizerResultTtlInSeconds: Int
var lambdaAuthorizerConfigAuthorizerUri: String?
var lambdaAuthorizerConfigIdentityValidationExpression: String?
var openIDConnectConfigAuthTTL: Int
var openIDConnectConfigClientId: String?
var openIDConnectConfigIatTTL: Int
var openIDConnectConfigIssuer: String?
var userPoolConfigAppIdClientRegex: String?
var userPoolConfigAwsRegion: String?
var userPoolConfigUserPoolId: String?
var ApiId: String? = jResp.StringOf("graphqlApi.apiId")
var Arn: String? = jResp.StringOf("graphqlApi.arn")
var AuthenticationType: String? = jResp.StringOf("graphqlApi.authenticationType")
var AuthorizerResultTtlInSeconds: Int = jResp.IntOf("graphqlApi.lambdaAuthorizerConfig.authorizerResultTtlInSeconds").intValue
var AuthorizerUri: String? = jResp.StringOf("graphqlApi.lambdaAuthorizerConfig.authorizerUri")
var IdentityValidationExpression: String? = jResp.StringOf("graphqlApi.lambdaAuthorizerConfig.identityValidationExpression")
var CloudWatchLogsRoleArn: String? = jResp.StringOf("graphqlApi.logConfig.cloudWatchLogsRoleArn")
var ExcludeVerboseContent: Int = jResp.IntOf("graphqlApi.logConfig.excludeVerboseContent").intValue
var FieldLogLevel: String? = jResp.StringOf("graphqlApi.logConfig.fieldLogLevel")
var Name: String? = jResp.StringOf("graphqlApi.name")
var AuthTTL: Int = jResp.IntOf("graphqlApi.openIDConnectConfig.authTTL").intValue
var ClientId: String? = jResp.StringOf("graphqlApi.openIDConnectConfig.clientId")
var IatTTL: Int = jResp.IntOf("graphqlApi.openIDConnectConfig.iatTTL").intValue
var Issuer: String? = jResp.StringOf("graphqlApi.openIDConnectConfig.issuer")
var v_String: String? = jResp.StringOf("graphqlApi.tags.string")
var UrisString: String? = jResp.StringOf("graphqlApi.uris.string")
var AppIdClientRegex: String? = jResp.StringOf("graphqlApi.userPoolConfig.appIdClientRegex")
var AwsRegion: String? = jResp.StringOf("graphqlApi.userPoolConfig.awsRegion")
var DefaultAction: String? = jResp.StringOf("graphqlApi.userPoolConfig.defaultAction")
var UserPoolId: String? = jResp.StringOf("graphqlApi.userPoolConfig.userPoolId")
var WafWebAclArn: String? = jResp.StringOf("graphqlApi.wafWebAclArn")
var XrayEnabled: Int = jResp.IntOf("graphqlApi.xrayEnabled").intValue
var i: Int = 0
var count_i: Int = jResp.SizeOfArray("graphqlApi.additionalAuthenticationProviders").intValue
while i < count_i {
jResp.I = i
authenticationType = jResp.StringOf("graphqlApi.additionalAuthenticationProviders[i].authenticationType")
lambdaAuthorizerConfigAuthorizerResultTtlInSeconds = jResp.IntOf("graphqlApi.additionalAuthenticationProviders[i].lambdaAuthorizerConfig.authorizerResultTtlInSeconds").intValue
lambdaAuthorizerConfigAuthorizerUri = jResp.StringOf("graphqlApi.additionalAuthenticationProviders[i].lambdaAuthorizerConfig.authorizerUri")
lambdaAuthorizerConfigIdentityValidationExpression = jResp.StringOf("graphqlApi.additionalAuthenticationProviders[i].lambdaAuthorizerConfig.identityValidationExpression")
openIDConnectConfigAuthTTL = jResp.IntOf("graphqlApi.additionalAuthenticationProviders[i].openIDConnectConfig.authTTL").intValue
openIDConnectConfigClientId = jResp.StringOf("graphqlApi.additionalAuthenticationProviders[i].openIDConnectConfig.clientId")
openIDConnectConfigIatTTL = jResp.IntOf("graphqlApi.additionalAuthenticationProviders[i].openIDConnectConfig.iatTTL").intValue
openIDConnectConfigIssuer = jResp.StringOf("graphqlApi.additionalAuthenticationProviders[i].openIDConnectConfig.issuer")
userPoolConfigAppIdClientRegex = jResp.StringOf("graphqlApi.additionalAuthenticationProviders[i].userPoolConfig.appIdClientRegex")
userPoolConfigAwsRegion = jResp.StringOf("graphqlApi.additionalAuthenticationProviders[i].userPoolConfig.awsRegion")
userPoolConfigUserPoolId = jResp.StringOf("graphqlApi.additionalAuthenticationProviders[i].userPoolConfig.userPoolId")
i = i + 1
}
// A sample JSON response body parsed by the above code:
// {
// "graphqlApi": {
// "additionalAuthenticationProviders": [
// {
// "authenticationType": "string",
// "lambdaAuthorizerConfig": {
// "authorizerResultTtlInSeconds": number,
// "authorizerUri": "string",
// "identityValidationExpression": "string"
// },
// "openIDConnectConfig": {
// "authTTL": number,
// "clientId": "string",
// "iatTTL": number,
// "issuer": "string"
// },
// "userPoolConfig": {
// "appIdClientRegex": "string",
// "awsRegion": "string",
// "userPoolId": "string"
// }
// }
// ],
// "apiId": "string",
// "arn": "string",
// "authenticationType": "string",
// "lambdaAuthorizerConfig": {
// "authorizerResultTtlInSeconds": number,
// "authorizerUri": "string",
// "identityValidationExpression": "string"
// },
// "logConfig": {
// "cloudWatchLogsRoleArn": "string",
// "excludeVerboseContent": boolean,
// "fieldLogLevel": "string"
// },
// "name": "string",
// "openIDConnectConfig": {
// "authTTL": number,
// "clientId": "string",
// "iatTTL": number,
// "issuer": "string"
// },
// "tags": {
// "string": "string"
// },
// "uris": {
// "string": "string"
// },
// "userPoolConfig": {
// "appIdClientRegex": "string",
// "awsRegion": "string",
// "defaultAction": "string",
// "userPoolId": "string"
// },
// "wafWebAclArn": "string",
// "xrayEnabled": boolean
// }
// }
}