Skip to content
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

*Edit* Graphql Update Appending Data to Arrays instead of overwriting #5541

Closed
Rafcin opened this issue Aug 24, 2020 · 13 comments
Closed

*Edit* Graphql Update Appending Data to Arrays instead of overwriting #5541

Rafcin opened this issue Aug 24, 2020 · 13 comments
Labels
pending-response Issue is pending response from the issue author

Comments

@Rafcin
Copy link

Rafcin commented Aug 24, 2020

I noticed a bug today, while I was working on an editor. When running the update mutation, my properties that use arrays are duplicated leaving me with the original array and the new array stored together. How the editor works is I get the data for x object, set the state and then with the same state if the user modified it and confirms it then it updates. I was under the impression it would override the values

@Rafcin
Copy link
Author

Rafcin commented Aug 25, 2020

Another issue that goes with this is that when I set the values to be null or empty the action goes through but never actually makes the arrays empty or null.

    await API.graphql(graphqlOperation(mutations.updateRestaurant, { input: {
      id: this.state.restaurantData.id,
      restaurantPaymentOptions: [],
      restaurantOpeningHours: [],
      restaurantImageHeaders: [],
    } }))

@Rafcin
Copy link
Author

Rafcin commented Aug 26, 2020

Would using AWSJSON be appropriate for this case?

@Rafcin Rafcin changed the title Duplicate Properties when running GraphQL update *Edit* Graphql Update Appending Data to Arrays instead of overwriting Aug 26, 2020
@Rafcin
Copy link
Author

Rafcin commented Aug 26, 2020

Also I should note that looking at other issues online I noticed some people had issues because of @versioned and I have the version stamps on my DynamoDB items and yet I never added the version tag to my schema....

@Rafcin
Copy link
Author

Rafcin commented Aug 26, 2020

Fixed it. The issue is caused by the conflict detection. Although I removed the conflict detection through the CLI I had to manually remove

        "project": {
            "ConflictHandler": "AUTOMERGE",
            "ConflictDetection": "VERSION"
        },

@ondojo
Copy link

ondojo commented Sep 24, 2020

Hi, we are actually facing the same problems, using DataStore (which requires us to use conflict detection) and hence removing that is not a probable solution for us.
The symptoms are, that occasionally an update of a model having an array attribute leads to a duplication of the array items.

I hope that description is somewhat understandable, if not, please let me know and I will try to elaborate in more detail.

@sammartinez sammartinez transferred this issue from aws-amplify/amplify-js Oct 9, 2020
@ammarkarachi
Copy link
Contributor

@ondojo do you mean the items are concatenated even though they are the same? Also could you share your tranform.conf file?

@ammarkarachi ammarkarachi added DataStore pending-response Issue is pending response from the issue author labels Oct 9, 2020
@stale
Copy link

stale bot commented Nov 9, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale
Copy link

stale bot commented Nov 21, 2020

This issue has been automatically closed because of inactivity. Please open a new issue if you are still encountering problems.

@stale stale bot closed this as completed Nov 21, 2020
@CarbnJacob
Copy link

I have this same problem too! With automerge the data objects concatenate every time rather than replace, which leads to huge issues.

@crolly
Copy link

crolly commented Dec 18, 2020

I have this same problem too! With automerge the data objects concatenate every time rather than replace, which leads to huge issues.

after some more digging into the docs of app sync, i have found this: https://docs.aws.amazon.com/appsync/latest/devguide/conflict-detection-and-sync.html

the leads me to believe, that everything works as it is supposed to.

Conflict on a list: GraphQL type and database type are lists. Concatenate the incoming list with the existing list in the server. The list values in the incoming mutation will be appended to the end of the list in the server. Duplicate values will be retained.

What we did, was to change the conflict resolution to Optimistic Concurrency and implementing our own conflict resolution.
@CarbnJacob you could e.g. use lodash's isEqual and then replace items in the list or the entire list. I guess it all depends on your data model.

@CarbnJacob
Copy link

@CarbnJacob you could e.g. use lodash's isEqual and then replace items in the list or the entire list. I guess it all depends on your data model.

Thanks for getting back to me so fast @crolly!

I'm new to conflict resolution - would this conflict resolution need to be done in the callback from failed GraphQL mutations made by the client?

I'm doing most of the saves through Amplify DataStore so it's largely a black box to me :(

@crolly
Copy link

crolly commented Dec 18, 2020

@CarbnJacob yes. take a look here: https://docs.amplify.aws/lib/datastore/conflict/q/platform/js#custom-configuration

you can specify your own conflictHandler with DataStore.configure.

@github-actions
Copy link

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pending-response Issue is pending response from the issue author
Projects
None yet
Development

No branches or pull requests

5 participants