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