DEV Community

Discussion on: Five reasons you should consider AppSync over API Gateway

Collapse
 
idavidasilva profile image
Davi da Silva

Nice! But I have one question about proxying from AppSync to DynamoDB, how do you validate the data and return an error response to the client?

Collapse
 
theburningmonk profile image
Yan Cui

What sorta validation are you thinking about? In most cases, you can check in the response template whether there's been an error, if so, you can throw a custom error, but even if you don't, AppSync will throw the DynamoDB error (e.g. conditional check failed). This error handling behaviour is different between the two versions of template though, it's something that trips me up from time-to-time too.

Collapse
 
idavidasilva profile image
Davi da Silva

I was talking about input validation like the middy middleware where you can check for Ajv input. So you can allow for example if the string is valid inside an array. I am curious now how you do this kind of validation with AppSync and Dynamo talking to each other without a lambda. (I never used AppSync and GraphQL)

Thread Thread
 
theburningmonk profile image
Yan Cui

Ah, I see. For those, you can perform validation in the VTL request template.