Validate user input in AppSync DynamoDB Resolvers

Solution 1:

I can't find a nice way of doing this in GraphQL, but you can do it easily in VTL using either $util.validate or $util.error (see the AWS documentation). They both have the same result of adding an item to the errors array.

Here's a demo of $util.validate: https://mappingtool.dev/app/appsync/bee55bd607e2166091451e7a7959318e

Here's a demo of $util.error: https://mappingtool.dev/app/appsync/006d6c05e8bb7257c6cebce34494994c