aws-appsync-community icon indicating copy to clipboard operation
aws-appsync-community copied to clipboard

Invalidate multiple subscriptions in a mutation

Open sashee opened this issue 3 years ago • 2 comments

I use $extensions.invalidateSubscriptions to close the subscription for users no longer allowed to receive updates and it works for a single subscription. But when I tried to invalidate multiple subscriptions, it seems that the last one overwrites the previous ones.

For example, users can subscribe to new files and documents:

type Subscription {
    onFileChanged: File
        @aws_subscribe(mutations: ["..."])
    onDocumentChanged: Document
        @aws_subscribe(mutations: ["..."])
}

Then I can delete the user:

type Mutation {
    deleteUser(userId: ID!): ID!
}

What I want is to close the deleted user's subscription to both files and documents:

$extensions.invalidateSubscriptions({
        "subscriptionField": "onFileChanged",
        "payload": {
                "userId": $ctx.args.userId
        }
    })

$extensions.invalidateSubscriptions({
        "subscriptionField": "onDocumentChanged",
        "payload": {
                "userId": $ctx.args.userId
        }
    })

But this does not work. If only one of the $extensions.invalidateSubscriptions is present, then the subscription is closed. But when both, only the second is effective. I also could not find any hints that a single $extensions.invalidateSubscriptions can specify multiple subscriptionFields.

Is it something that is supported by AppSync and the problem is on my end, or a single mutation can only terminate connections to a single subscriptions?

sashee avatar May 12 '22 13:05 sashee

Current behavior is that a single mutation can only terminate a single subscription. When you attempt to terminate more than one subscription in a single request it will only terminate the last subscription in the mutation. I've added work to enable termination of multiple subscriptions in a single request into our backlog.

billfine avatar May 14 '22 01:05 billfine

Thank you, I'm looking forward to it!

sashee avatar May 14 '22 06:05 sashee

Would also love this feature, where would I be able to track this backlog item?

ntharakan avatar Jan 18 '23 15:01 ntharakan

Hello,

This feature is live now. Please check AppSync docs for more details.

Thanks

yashpatel6892 avatar Mar 07 '23 00:03 yashpatel6892

Hi @billfine May I know how the state of terminating more than one subscription ? it will be useful for development., Thanks

godisren avatar Mar 19 '23 14:03 godisren