My first impression
AWS AppSync:
GraphQL API Managed service
Resolver:
AppSyncのデータ変換の処理を記述する箇所
defaultではVTLで記述する
Managed Service なので便利
Subscriptionも
すぐに使える
DynamoDBとの組み合わせて簡単に始められる
serverless frameworkでも
サポートされている
VTLって何!
DynamoDB
ムズい
serverless frameworkの offline実行が便利
#set($expression = "")
#set($expressionNames = {})
#set($expressionValues = {})
#foreach($key in $ctx.args.input.keySet())
#if ($expression.length().equals(0))
#set($expression = "SET #$key = :$key")
#else
#set($expression = "${expression}, #$key = :$key")
#end
$util.qr($expressionNames.put("#$key", $key))
$util.qr($expressionValues.put(":$key", $ctx.args.input.get($key)))
#end
{
"version" : "2018-05-29",
"operation" : "UpdateItem",
"key" : {
"key": $util.dynamodb.toDynamoDBJson($ctx.args.key)
},
"update" : {
"expression": "$expression",
"expressionNames": $util.toJson($expressionNames),
"expressionValues": $util.dynamodb.toMapValuesJson($expressionValues)
}
}
## [Start] Determine request authentication mode **
#if( $util.isNullOrEmpty($authMode) && !$util.isNull($ctx.identity) && !$util.isNull($ctx.identity.sub) && !$util.isNull($ctx.identity.issuer) && !$util.isNull($ctx.identity.username) && !$util.isNull($ctx.identity.claims) && !$util.isNull($ctx.identity.sourceIp) && !$util.isNull($ctx.identity.defaultAuthStrategy) )
#set( $authMode = "userPools" )
#end
## [End] Determine request authentication mode **
## [Start] Check authMode and execute owner/group checks **
#if( $authMode == "userPools" )
## [Start] Owner Authorization Checks **
#set( $isOwnerAuthorized = false )
## Authorization rule: { allow: owner, ownerField: "owner", identityClaim: "cognito:username" } **
#set( $allowedOwners0 = $util.defaultIfNull($ctx.args.input.owner, null) )
#set( $identityValue = $util.defaultIfNull($ctx.identity.claims.get("username"), $util.defaultIfNull($ctx.identity.claims.get("cognito:username"), "___xamznone____")) )
#if( $util.isList($allowedOwners0) )
#foreach( $allowedOwner in $allowedOwners0 )
#if( $allowedOwner == $identityValue )
#set( $isOwnerAuthorized = true )
#end
#end
#end
#if( $util.isString($allowedOwners0) )
#if( $allowedOwners0 == $identityValue )
#set( $isOwnerAuthorized = true )
#end
#end
#if( $util.isNull($allowedOwners0) && (! $ctx.args.input.containsKey("owner")) )
$util.qr($ctx.args.input.put("owner", $identityValue))
#set( $isOwnerAuthorized = true )
#end
## [End] Owner Authorization Checks **
## [Start] Throw if unauthorized **
#if( !($isStaticGroupAuthorized == true || $isDynamicGroupAuthorized == true || $isOwnerAuthorized == true) )
$util.unauthorized()
#end
## [End] Throw if unauthorized **
#end
## [End] Check authMode and execute owner/group checks **
それならDynamoDB を使う必要もなかったね
Lambda
Resolverで
良くない?
DynamoDBは癖強すぎ
serverless frameworkは 神
GraphQLのschemaでtimestampは何の型で定義していますか?
標準のScalarとしては以下の5つだけ
timestampとしてunix timeを採用する場合、
32bit signed-integerなのでミリ秒が含められない&2038年問題があります。
64bit の整数型があれば、ミリ秒もしくはマイクロ秒まで含められるのですが、AWS AppSyncではCustom Scalar typeを追加することができないため無理でした。
仕方ないので、今回は文字列で時刻をISO 8601フォーマットにしたものを使うことにしました。追加でサーバ側で受け取った文字列を、正規化してタイムゾーンをUTCに変換する処理を入れてます。
変換処理が必要なのはbackendがDynamoDBなので、Datetimeを保存する用の型が用意されていないため、ただの文字列として保存しないとならないのが原因ですかね?
他のプロジェクトではどうしているか、聞きたいです。