I am use AWS AppSync and AWS Amplify
I have 2 models:
type Post {
id: ID!
title: String!
description: String
createdAt: String
}
type User {
id: ID!
username: String!
age: Int!
}
I create a custom req.vtl file like that:
## [Start] Initialization default values. **
$util.qr($ctx.stash.put("defaultValues", $util.defaultIfNull($ctx.stash.defaultValues, {})))
#set( $createdAt = $util.time.nowISO8601() )
$util.qr($ctx.stash.defaultValues.put("id", $util.autoId()))
$util.qr($ctx.stash.defaultValues.put("createdAt", $createdAt ))
$util.qr($context.args.input.put("createdAt", $createdAt ))
$util.toJson({
"version": "2018-05-29",
"payload": {}
})
## [End] Initialization default values. **
Everything works perfectly fine but I would like to know how to query the database inside resolver?
Example 1: I want to check if the post.title already exist in other post.
$ctx.args.input.title
If yes, I will create a error:
$util.error("This post already exist")
Example 2: I want to check if the user is over 18 years old.
$ctx.args.input.userId
If no, I will create a error:
$util.error("Your are too young!")
What I want to know is how to communicate with the database (without use lambda function). Can you help me?
If you are other example, you are welcome.
Regards