Type: AWS::AppSync::Resolver
Properties:
  ApiId: !GetAtt AppSyncAPI.ApiId
  DataSourceName: !GetAtt AppSyncDynamoDBMaterialSource.Name
  TypeName: "Work"
  FieldName: "materials"
  RequestMappingTemplate: |
    #set( $ListRequest = {
      "version": "2018-05-29",
      "operation": "Scan"
    } )
    #set( $idList = [] )
    #if( !$util.isNullOrEmpty($context.source.materials) )
      #foreach( $item in $context.source.materials )
        $util.qr($idList.add({"id": {"eq": $item}, "owner": {"eq": $context.source.owner}}))
      #end
      #set( $filterExpr = {"or": $idList} )
      #set( $ListRequest.filter = $util.parseJson("$util.transform.toDynamoDBFilterExpression($filterExpr)") )
    #else
      #return
    #end
    $util.toJson($ListRequest)
  ResponseMappingTemplate: |
    #if( $ctx.error )
      $util.error($ctx.error.message, $ctx.error.type)
    #else
      $util.toJson($ctx.result.items)
    #end