DEV Community

loading...

Simple Todo - Part 6 of 6

Related Code
Mobile Application Development. Scalable Architecture Design. Custom Backend Development. Application Security. Performance Engineering. Analytics. Maintenance.
・1 min read

It is a general requirement to have a server-side timestamp on every database action.

In our Todo demo apps, we will have the updatedAt value to be changed by the server.

In the AppSync Schema dashboard find and open the Mutation Resolvers (createTodo and updateTodo) one by one.

Screenshot

Insert a single line of code before the existing mapping template.

$util.qr($context.arguments.input.put("updatedAt", $util.time.nowISO8601()))
Enter fullscreen mode Exit fullscreen mode

Screenshot

Save the resolver, and that's all. Don't forget to make these changes for all the mutations you need. In our case both createTodo and updateTodo.

Next time, when we are sending a Todo mutation to the server, the AppSync resolver will automatically override the updatedAt value. So whenever the modified item is bouncing back from the server (by a query or by a subscription) we will find the server-side timestamp in the updatedAt field (instead of what we saved locally).

It might seem complicated first, but if you implement it as described above, it just simply works.

Discussion (0)