Type: AWS::AppSync::Resolver
Properties:
  ApiId: !GetAtt AppSyncAPI.ApiId
  TypeName: "Mutation"
  FieldName: "batchCreateMechanism"
  DataSourceName: !GetAtt AppSyncDynamoDBMechanismSource.Name
  RequestMappingTemplate: |
    #set($items = [])
    #foreach($item in $ctx.args.input)
      $util.qr($item.put("id", $util.defaultIfNull($item.id, $util.autoId())))
      $util.qr($item.put("owner", $ctx.identity.sub))
      $util.qr($item.put("sort", $item.id))
      #set( $createdAt = $util.time.nowISO8601() )
      $util.qr($item.put("createdAt", $util.defaultIfNull($item.createdAt, $createdAt)))
      $util.qr($item.put("updatedAt", $util.defaultIfNull($item.updatedAt, $createdAt)))
      $util.qr($item.put("__typename", "Mechanism"))
      $util.qr($items.add($util.dynamodb.toMapValues($item)))
    #end
    {
      "version" : "2018-05-29",
      "operation" : "BatchPutItem",
      "tables" : {
        "${self:provider.environment.MECHANISM_TABLE}": $utils.toJson($items)
      }
    }
  ResponseMappingTemplate: |
    #if( $ctx.error )
      $util.error($ctx.error.message, $ctx.error.type)
    #else
      $util.toJson($ctx.result.data.${self:provider.environment.MECHANISM_TABLE})
    #end