0
votes

I want my React web app to receive messages using AWS AppSync subscriptions for mutations that are computed asynchronously, based on mutations to types other than the type the client originally submitted a request to mutate. For example, if a user casts a "vote", I want the server to respond immediately, but the server should also send clients the aggregations of the overall database that might take extra time to compute or can be computed at a slower rate.


I assume AppSync will notify clients if they make a Graphql subscription, lets say, to the type "Aggregation".

Q1. Will a web client receive a message for the Aggregation subscription if I write a server-side client that writes the Aggregation mutation to the AppSync API EVEN after the client received a response from the original vote request?


I assume I will need to make a server-side Graphql client to write the aggregation mutation. I guess this is as simple as a http client.

Q2. How can I trigger the code that computes the aggregation when at least one user has submitted a mutation (vote)? My best guess is that I need to use a Lambda Function to handle the original mutation (vote), but before responding to the web client, it will start another process (maybe a different Lambda Fn) which will eventually mutate the aggregation.


I have not yet integrated the Apollo client so I'd like to keep the web client side code simple for now.

1

1 Answers

1
votes

If I understand your question you want to something to kick off the aggregation process and then get a subscription message when there's a new aggregate. To kick off the aggregation you could use any number of things depending on where you're storing your data. For example, if you're using DynamoDB you could use DynamoDB streams to kick off an aggregation when there's a change to vote. Or, like you said, you could kick off a lambda or another process in response to the subscription message to vote. Any of these solutions would need to make a mutation to write the aggregate which will result in a subscription message to clients subscribed to Aggregation.