Search code examples
amazon-web-servicesaws-appsyncvtl

In AWS Resolver Mapping Template, is there any method for removing a field from an object?


I'm writing code for my GraphQL resolvers in AWS AppSync with resolver mapping template.

I know that there is a put mehtod that I can use for add a field to input object or any other object. Like this (for example):

$util.qr($name.put("firstName", "$ctx.args.input.firstName"))

But now I want to remove a field from an object, for example, the input object. Is there any mehtod similar to the put method but for removing a field. something like:

$util.qr($ctx.args.input.remove("firstName"))

I am new to AWS and DynamoDB and AppSync.( you can consider me as an absolute beginner. )


Solution

  • Use foreach and make a new array.

    #set($newInput={})
    
    #foreach ($key in $ctx.args.input.keySet())
      #if($key!="firstName")
         $util.qr($newInput.put($key, $ctx.args.input.get($key)))
      #end
    #end