awslabs / aws-mobile-appsync-sdk-ios

iOS SDK for AWS AppSync.
https://awslabs.github.io/aws-mobile-appsync-sdk-ios/
Other
262 stars 130 forks source link

How to avoid duplicate mutations when the app is backgrounded/quit before the mutation is finished? #576

Closed tomsinqg closed 11 months ago

tomsinqg commented 1 year ago

We are currently using this library as part of a chat function in our app, however we are getting duplicate messages due to the offline mutation function. When a user sends a message and then backgrounds the app while in low power mode the mutation goes up and the message is sent, however the deleting of the offline mutation doesn't get a chance to be called. This means that when the app re-opens it attempts to send that same message again, leading to a duplicate message.

Is there a way to resolve this? Looking through the documentation I can't find any way to reconcile these two messages without disabling the offline ability altogether which could lead to messages getting lost entirely which we don't want.

Environment(please complete the following information):

Device Information (please complete the following information):

lawmicha commented 1 year ago

How are you provisioning the AppSync backend, what does your schema look like?

An example of the request and response would be helpful or if you provide more details to what a duplicate message means in this case. Is it a new chat message with identical content but different primary key value? Or is it that the message is updated twice with the same content?