Type: AWS::AppSync::Resolver
Properties:
  ApiId: !GetAtt AppSyncAPI.ApiId
  TypeName: "Mutation"
  FieldName: "deleteMaterial"
  DataSourceName: !GetAtt AppSyncDynamoDBMaterialSource.Name
  RequestMappingTemplate: |
    #set( $condition = {
      "expression": "attribute_exists(#id)",
      "expressionNames": {
          "#id": "id"
      }
    } )
    #if( $context.args.condition )
      #set( $conditionFilterExpressions = $util.parseJson($util.transform.toDynamoDBConditionExpression($context.args.condition)) )
      $util.qr($condition.put("expression", "($condition.expression) AND $conditionFilterExpressions.expression"))
      $util.qr($condition.expressionNames.putAll($conditionFilterExpressions.expressionNames))
      #set( $conditionExpressionValues = $util.defaultIfNull($condition.expressionValues, {}) )
      $util.qr($conditionExpressionValues.putAll($conditionFilterExpressions.expressionValues))
      #set( $condition.expressionValues = $conditionExpressionValues )
      $util.qr($condition.expressionValues.putAll($conditionFilterExpressions.expressionValues))
    #end
    #if( $condition.expressionValues && $condition.expressionValues.size() == 0 )
      #set( $condition = {
      "expression": $condition.expression,
      "expressionNames": $condition.expressionNames
    } )
    #end
    {
      "version": "2018-05-29",
      "operation": "DeleteItem",
      "key": {
        "owner": $util.dynamodb.toDynamoDBJson($ctx.identity.sub),
        "sort": $util.dynamodb.toDynamoDBJson($ctx.args.input.id)
      },
      "condition": $util.toJson($condition)
    }
  ResponseMappingTemplate: |
    #if( $ctx.error )
      $util.error($ctx.error.message, $ctx.error.type)
    #else
      $util.toJson($ctx.result)
    #end