aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.43k stars 2.12k forks source link

GraphQL update query not working #8704

Closed asatvilker closed 3 years ago

asatvilker commented 3 years ago

Before opening, please confirm:

JavaScript Framework

React

Amplify APIs

GraphQL API

Amplify Categories

api

Environment information

``` # Put output below this line System: OS: macOS 11.2.1 CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz Memory: 811.55 MB / 16.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 14.15.5 - /usr/local/bin/node npm: 6.14.11 - /usr/local/bin/npm Browsers: Chrome: 92.0.4515.107 Edge: 91.0.864.54 Firefox: 85.0.2 Safari: 14.0.3 npmPackages: @aws-amplify/ui-react: ^0.2.14 => 0.2.14 @testing-library/jest-dom: ^4.2.4 => 4.2.4 @testing-library/react: ^9.5.0 => 9.5.0 @testing-library/user-event: ^7.2.1 => 7.2.1 aws-amplify: ^3.0.17 => 3.0.17 aws-sdk: ^2.735.0 => 2.735.0 mdbreact: ^4.27.0 => 4.27.0 node-sass: ^4.14.1 => 4.14.1 react: ^16.13.1 => 16.13.1 react-circular-progressbar: ^2.0.3 => 2.0.3 react-dom: ^16.13.1 => 16.13.1 react-hook-form: ^6.0.4 => 6.0.4 react-markdown: ^4.3.1 => 4.3.1 react-router-hash-link: ^1.2.2 => 1.2.2 react-scripts: 3.4.1 => 3.4.1 react-typewriting-effect: ^1.0.3 => 1.0.3 react-typist: ^2.0.5 => 2.0.5 update-json-file: ^1.1.1 => 1.1.1 npmGlobalPackages: @aws-amplify/cli: 4.43.0 create-react-app: 3.4.1 gatsby-cli: 2.19.1 mdb-cli: 1.1.34 npm: 6.14.11 test: 0.6.0 ```

Describe the bug

When running a graphQL update query, the query does not return an error however it is not updating the item. The result of the query is not an error but if you look at the values meant to have been updated, they are still the same and the updatedAt timestamp has also not changed.

Screenshot 2021-08-04 at 11 21 11

Expected behavior

The query should update the values specified

Reproduction steps

setup a graphQL api from the amplify cli in your project

then go to the AWS console -> appsync -> select your api -> queries

in the editor run a similar update query as shown below. As you can see it does not return an error but it is not updating the title, the result shows the title is still 'Python' not 'PythonUpdated'

Screenshot 2021-08-04 at 11 21 11

Code Snippet

// Put your code below this line.
mutation MyMutation5 {
  updatePortfolioCategory(input: {id: "8661eb26-11d6-4be3-a71c-b314e0d5ff43", topic: "PythonUpdated"}) {
    topic
    updatedAt
  }
}

Log output

``` // Put your logs below this line 179ddcf3-425d-4845-bc8a-581cef60bbef Begin Request 179ddcf3-425d-4845-bc8a-581cef60bbef Conflict Resolution flow:{"conflictType":"Conflict encountered on version mismatch between client and server. Server had an item version of \u002720\u0027.","conflictHandlerConfigured":"AUTOMERGE","message":"AUTOMERGE was executed on the conflicting items.","data":{"__typename":"REJECTED","topic":"REJECTED","updatedAt":"REJECTED"},"syncAttempt":1} { "duration": 88836822, "logType": "ExecutionSummary", "requestId": "179ddcf3-425d-4845-bc8a-581cef60bbef", "startTime": "2021-08-04T12:25:11.202996Z", "endTime": "2021-08-04T12:25:11.291832Z", "parsing": { "startOffset": 272202, "duration": 262979 }, "version": 1, "validation": { "startOffset": 714300, "duration": 438891 }, "graphQLAPIId": "ryxjza6hxrghzbtfyulwra67qy" } { "logType": "RequestSummary", "requestId": "179ddcf3-425d-4845-bc8a-581cef60bbef", "graphQLAPIId": "ryxjza6hxrghzbtfyulwra67qy", "statusCode": 200, "latency": 106365000 } 179ddcf3-425d-4845-bc8a-581cef60bbef End Request ```

aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

chrisbonifacio commented 3 years ago

Hey @asatvilker 👋 Are you using DataStore in your app? Also, are you experiencing the same behavior when updating records from your application or is this only happening on the AppSync console?

chrisbonifacio commented 3 years ago

Well, I was able to reproduce this pretty quickly and consistently. Will look into this further and bring it to the team's attention. Thank you!

Screen Shot 2021-08-04 at 11 45 29 AM
chrisbonifacio commented 3 years ago

Spoke to a member of the AppSync team today about this issue and, as it turns out, because your API has DataStore enabled and Auto Merge as the Conflict Handler, you simply need to include the _version of the record you're trying to update. If you take a look at the graphql queries DataStore makes in the browser, you can see it included in the variables.

False alarm! 😅 haha

Screen Shot 2021-08-04 at 5 20 40 PM

In the AppSync console

Screen Shot 2021-08-04 at 5 24 40 PM
asatvilker commented 3 years ago

I see, thank you for your help, just wondering if its possible to remove data store then as this is more problematic? I tried using the amplify cli to update api -> graphQL -> remove data store from api. However then the queries dont work at all? Is there anyway to reverse the use of data store back to how it was? I just enabled data store i didn’t actively start using it so sort of no point having it. Thanks again for the support

chrisbonifacio commented 3 years ago

Hey @asatvilker. DataStore would automatically include the version of the record being updated when it triggers the GraphQL mutations from your application. What behavior are you seeing when attempting to perform queries through the AppSync console now that DataStore is disabled? I just tried disabling DataStore for my app through the CLI (be sure to run amplify push after doing so), and it seems to have just removed the _version, _lastChangedAt, etc fields but I am still able to query the data.

Screen Shot 2021-08-05 at 5 19 02 PM
chrisbonifacio commented 3 years ago

Looking over your environment information it seems you're behind on amplify updates. Is there a reason you haven't upgraded aws-amplify to v4 and/or the CLI to v5? I believe there used to be issues on older versions where the API data had to be cleared after removing DataStore for it to work afterwards. I'll have to double check on that though. Might be worth trying in your dev environment to see if it gets your queries working again.

asatvilker commented 3 years ago

Hi @chrisbonifacio . I did the same to disable and also I did run amplify push. However when running an update mutation on appsync it would return an error. The error is essentially saying that it is looking for the _version but of course that has been removed.

I haven’t done any updates, haven’t used amplify in a while ahaha. Perhaps that is the reason!

chrisbonifacio commented 3 years ago

@asatvilker We have these pages to help with upgrading the CLI and packages respectively.

https://docs.amplify.aws/cli/usage/upgrade

https://docs.amplify.aws/lib/troubleshooting/upgrading/q/platform/js

Let me know if updating helps! Otherwise, we can continue to work together towards getting you in a working state 😄

chrisbonifacio commented 3 years ago

Hi 👋 Closing this as we have not heard back from you. If you are still experiencing this issue and in need of assistance, please feel free to comment and provide us with any information previously requested by our team members so we can re-open this issue and be better able to assist you. Thank you!

github-actions[bot] commented 2 years ago

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 or Discussions for those types of questions.