-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there a way for queries to wait for mutations to finish? #107
Comments
Yes, the mutation and query behavior is as per the architecture of the AppSync. Mutations are put into a queue and executed in a sequential fashion and respect the calling order; Queries are not enqueued and are executed independent of the mutation queue. An interesting area would be to look into the Client Architecture section in https://aws-amplify.github.io/docs/android/api. This section talks about how you can power the UI using a combination of client side caching/responseFetcher semantics, and prepping the cache by writing "optimistic responses" and updating them with "actual responses" received when executing mutations. I am also adding @undefobj and @nikhil-dabhade to this thread to provide their thoughts |
@gitnarqt could you go into a layer deeper around the application experience you're trying to deliver, and possibly any code/layout examples around the use case? It's not immediately clear to me why you would perform queries in such succession for overlapping data structures since, by GraphQL spec definition, a mutation is a write followed by an immediate fetch which would fulfill the data requirements. cc @palpatim |
Hey guys, thank for the quick response! I'll look more into the architecture, might have missed something. @undefobj we're working on an image gallery app that could be used offline and online. Our users could edit their images offline and at some point when they connect online, they have the ability to refresh their gallery and download their images from the cloud. The issue is occurring when they edit a lot of images in offline mode, then go online and refresh their gallery. Currently, we fixed it by waiting for mutationQueue to finish all mutations before performing any query - not sure this is the optimal way. |
@gitnarqt thanks for the information on how your app works. I've been thinking about this the past day and I wonder, how would you expect this to work otherwise? Do you want all queries to be blocked until the mutation queue is drained? Or would you want all queries to be executed first? The current design allows UX updates independent of mutations, and if there is a change to the data the client can receive a subscription notification. |
Sorry for the late response @undefobj. Thanks for the tip! We didn't implement subscription which I think would solve the issue we're facing with inconsistent data. Eventually, the user will be editing outdated images but I assume a conflict resolver would handle such a case. Thanks again! |
@gitnarqt I'm facing the same issue. Can you elaborate how implementing a subscription would solve this issue? |
@HashCode55 we didn't use subscription as it would require some time to implement. What we ended up doing is waiting for the mutation queue to be empty before performing any query from the cloud. This solved our problem and so far it's running smoothly! |
@gitnarqt Thanks for the fast response. I'm suffering from the same problem right now! I'm using javascript SDK though, can you send me a snippet how you are waiting on the mutation queue? I couldn't find any documented source. Edit: And how are you handling the case if the user reopens the app and is still offline? Waiting on the mutation queue would halt the app in this case or do you explicitly check the network connection as well? |
@HashCode55 we're using the Java SDK version which includes the isMutationQueueEmpty() and the clearMutationQueue(). Check issue #96 for a sample code As for the check, indeed we do a network check. If there is no internet, we just prevent it from waiting for the mutation queue. Hope this helps! |
Hello,
We're facing some inconsistency in the data when it comes to executing several mutations and queries at the same time. According to our tests, query operations are not enqueued in the same queue as the mutation operations and thus don't respect the calling order. Is that correct?
Example of deleting images:
This might cause confusion for our clients. Is this a bug or is it a correct behaviour of AppSync?
Thanks!
The text was updated successfully, but these errors were encountered: