aws-amplify / amplify-cli

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development.
Apache License 2.0
2.81k stars 821 forks source link

How to modify generated update resolver to support create-or-update? #1812

Closed kwhitejr closed 5 years ago

kwhitejr commented 5 years ago

Note: If your question is regarding the AWS Amplify Console service, please log it in the official AWS Amplify Console forum

Which Category is your question related to? Api: Appsync generated code.

What AWS Services are you utilizing? Appsync

Provide additional details e.g. code snippets I simply want to modify certain generated resolvers (i.e. Mutation.updateXYZ.req.vtl) to support create-or-update, in order to cut down on have a bunch of conditional checks in front end code.

In the most straightforward form of the issue, the update resolver requires an id field that does not yet exist. For example:

{
  "version": "2017-02-28",
  "operation": "UpdateItem",
  "key": #if( $modelObjectKey ) $util.toJson($modelObjectKey) #else {
  "id": {
      "S": "$context.args.input.id" // if this doesn't exist, create with $util.autoId()
  }
} #end,
  "update": $util.toJson($update),
  "condition": $util.toJson($condition)
}

Essentially I don't understand where in the generated updateXYZ vtl code to put a check for an id input + autoId if missing.

kaustavghosh06 commented 5 years ago

@kwhitejr You could use Custom resolvers to overwrite the auto-generated transformer resolvers. You can find more documentation out here - https://aws-amplify.github.io/docs/cli-toolchain/graphql#custom-resolvers Please feel free to re-open this issue if you're still stuck.

kwhitejr commented 5 years ago

@kaustavghosh06 Hi Kaustav, thanks for the quick replay. I know about replacing resolvers, and usually I can get away with minor adjustments to the generated code. For the mutation update resolver code, however, I'm a little overwhelmed, not sure where to start.

github-actions[bot] commented 3 years ago

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.