AWS Amplify: How custom Resolver?

Viewed 135

I'm learning to use AWS Amplify and need some guidance.
This is my schema.graphql file content (it's the default Queries):

type Blog @model {
  id: ID!
  name: String!
  posts: [Post] @hasMany
}

type Post @model {
  id: ID!
  title: String!
  blog: Blog @belongsTo
  comments: [Comment] @hasMany
}

type Comment @model {
  id: ID!
  post: Post @belongsTo
  content: String!
}

After run the command: amplify push

Amplify generate automatic code in the AWS Console (eg Service AppSync):

Example 1: Schema

enter image description here

Example 2: Mutation

enter image description here

My problem is that I don't know how to customize the resolvers because AWS AWS will overwrite my code.
Example: Now there is this code:

## [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($ctx.stash.defaultValues.put("updatedAt", $createdAt))
$util.toJson({
  "version": "2018-05-29",
  "payload": {}
})
## [End] Initialization default values. **

How can I do that with AWS Amplify:

## [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", "Hello"+$util.autoId()))
$util.qr($ctx.stash.defaultValues.put("createdAt", "2022-06-13T12:43:14.047Z"))
$util.qr($ctx.stash.defaultValues.put("updatedAt", "2022-06-13T12:43:14.047Z"))
$util.toJson({
  "version": "2018-05-29",
  "payload": {}
})
## [End] Initialization default values. **

How can I custom Resolver without overwriting issue?

Thanks you

1 Answers
Related