Idan Lottan
Idan Lottan

Reputation: 138

Creating custom appsync resolvers or lambda functions that are called when a certain event happens

I am developing an application using AppSync and I need some customization, for example - I want to have an invitation model which has an id which is the invitation code and have a user field which is connected to the user model, whenever creating a user the input requires giving an invitation id (the invitation code) but it only connects the user to the invitation, but not the invitation to the user.

I have tried reading about custom resolvers but they use a special language which is pretty difficult to learn because their docs are not so helpful. I tried looking for how to make a lambda function with aws amplify and then I ran into this problem https://github.com/aws-amplify/amplify-cli/issues/997.

So the functionality I currently need is this - an admin creates and invitation model and gives it an id and a user field which is null at first. When a user (also a model) is created one of the input fields is the invitation id which connects the invitation to the user so I can get the invitation when querying the user, but this way I cannot query the user through the invitation, so I wanted to make a lambda function that after creating a user will hook up the user id to the invitation table, how can I do something like that?

Upvotes: 1

Views: 649

Answers (1)

Ashwin Devendran
Ashwin Devendran

Reputation: 421

There are a couple ways to go about solving this problem. The easiest would probably be to set up Pipeline Resolvers. See the documentation for that here https://docs.aws.amazon.com/appsync/latest/devguide/pipeline-resolvers.html

Essentially, what you would setup would be a createUser mutation with the resolver being Pipeline. In the first function you would create your user, in the next function that follows you connect the user id to the invitation.

Definitely follow along with some of the tutorials here for Pipeline resolvers as this would solve your use case: https://docs.aws.amazon.com/appsync/latest/devguide/tutorial-pipeline-resolvers.html#aws-appsync-tutorial-pipeline-resolvers

Upvotes: 2

Related Questions