Reputation: 198
I am developing a web application using AWS Amplify and AppSync to read and write my data to DynamoDB tables. Using the Amplify's GraphQL Transforms, it is easy enough to establish a connection between data types using the @connection
transform. I wish to know if it is possible to delete related data in a simplified or semi-automated way.
Supposing a simple blog example, where a user has a blog, which has posts, which in turn has comments owned by other users. If a post is deleted, I would like to delete the comments associated with that post. If a user is deleted, I would like to delete their blog(s), posts, and comments related to those posts, and any comment the user has left on other posts. This example is contrived in that perhaps it is desirable to have some of this data be maintained in some form. However, in some cases this behaviour is exactly what I am looking for.
When working with Prisma in the past, I used their @relation
directive to make a relationship similar to using Amplify's @connection
.
However, in cases where I wanted cascading deletion, I would write something along the lines of:
type Post {
id: ID! @unique
title: String!
body: String!
owner: ID!
comments: [Comment!] @relation(name: "PostComments",
onDelete: CASCADE)
}
I could use and set the onDelete
parameter to CASCADE
or SET_NULL
depending on how I wanted to handle it.
Is there a way to do something similar through Amplify? Of course I can write a bunch of VTL or Lambda resolvers to handle each case, but I wanted to check first if there is a faster / easier way to implement this.
Upvotes: 3
Views: 1753
Reputation: 3683
This is not yet supported natively by Amplify. As you said, you are able to replicate this behavior using pipeline resolvers & some VTL and then deploy that via the Amplify CLI or on your own. There are plans to allow you to write your own transformers to encode reproducible logic like this as a resolver (see https://github.com/aws-amplify/amplify-cli/issues/1060) as well as plans to move towards pipeline resolvers for all Amplify CLI projects (see https://github.com/aws-amplify/amplify-cli/issues/1055).
Upvotes: 2