This repo demonstrates the DataStore error related to syncing. Follow the steps below to reproduce. I have recorded to terminal session of my demonstration which can be found in /output.txt.
To reproduce:
- npx create-react-app datastore-demo
- cd datastore-demo
- npx amplify-app@latest
- amplify init
- change schema.graphql to
type User @model { id: ID! firstName: String! lastName: String! }
- amplify codegen models
- amplify push
- npm i @aws-amplify/datastore @aws-amplify/core
- Change App.js to
import React from 'react'; import { DataStore } from '@aws-amplify/datastore'; import { User } from './models';
function App() { const handleAddUser = async () => { try { const newUser = await DataStore.save( new User({ firstName: 'aws', lastName: 'datastore' }), ); console.log('new user :', newUser); } catch (e) { console.error('failed to add user: ', e); } };
return (
export default App;
- npm start
- Click the button to add a User
- Check the console, and you will see:
- new user: [Model] 0: {firstName: ‘aws’, lastName: ‘datastore’, id:’x’, _version: undefined, _lastChangedAt: undefined, _deleted: undefined}
- (Some minutes later) failed to add user:
- (More importantly) check the User dynamodb table and you will not find any new items