aws-amplify / amplify-category-api

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development. This plugin provides functionality for the API category, allowing for the creation and management of GraphQL and REST based backends for your amplify project.
https://docs.amplify.aws/
Apache License 2.0
89 stars 79 forks source link

Batch Delete Join Table Item When Original Item Is Deleted - Graphql Mutations #644

Closed LoukasGP closed 1 year ago

LoukasGP commented 2 years ago

Which Category is your question related to? API.graphql mutation

Amplify CLI Version Version: 8.0.1

What AWS Services are you utilizing? AppSync

Provide additional details e.g. code snippets. Be sure to remove any sensitive data.

I've come across this documentation that notes batch is not supported, and thus requires a custom resolver.

I've also come across this feature request for cascading delete with DynamoDB Streams and Lambda.

I see there is an example for a batch put custom resolver, however, I'm new to VTL transformers, and would like some guidance for setting up a batch delete transformer.

Use Case:

There is a @model for JobListing, and one for Images. They have a ManyToMany Relationship. When I delete an Image record from DynamoDB, all JobListingImage records for that image need to be deleted as well.

I've considered looping through the JobListingImage records, but there could be a possiblity where there are 100,000 records to query and then delete. This does not appear like a good, nor viable solution.

Any help would be appreciated,

Luke

sundersc commented 2 years ago

Hi @LoukasGP - Your usecase can be achived by AppSync's BatchDeleteItem operation.

Here is an example of BatchDeleteItem operation from AppSync docs. https://docs.aws.amazon.com/appsync/latest/devguide/tutorial-dynamodb-batch.html

VTL programming guide: https://docs.aws.amazon.com/appsync/latest/devguide/resolver-mapping-template-reference-programming-guide.html#aws-appsync-resolver-mapping-template-reference-programming-guide

AppSync resolver tutorials: https://docs.aws.amazon.com/appsync/latest/devguide/tutorials.html

Please see if these help. Let us know if you have questions.