0

I am building grpahql on Appsync and use websocket as subscription communication channel. Below is the scheme:

type Subscription {
    addedPost: Post
    @aws_subscribe(mutations: ["addPost"])
    updatedPost: Post
    @aws_subscribe(mutations: ["updatePost"])
    deletedPost: Post
    @aws_subscribe(mutations: ["deletePost"])
}

and I will attach lambda as the resolver for these subscription fields. In the schema, each subscription fields returns Post as response type. In my lambda resolver, what should I return? In the lambda, it doesn't know anything about Post because Post is used in the mutation. I don't understand what I should return in the subscription resolver lambdas.

Joey Yi Zhao
  • 37,514
  • 71
  • 268
  • 523

1 Answers1

1

If you read the AppSync docs (https://docs.aws.amazon.com/appsync/latest/devguide/real-time-data.html) you will find the following:

Subscriptions are triggered from mutations and the mutation selection set is sent to subscribers.

You don't need to attach resolvers for subscriptions with AppSync. AppSync takes care of this for you. By using the @aws_subscribe directive you are associating the response of the addPost mutation to the the addedPost subscription.

You would just need to ensure, in this case, that the addedPost selection set is a subset of the addPost selection set.