DataStore not syncing on new project
See original GitHub issueBefore opening, please confirm:
- I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
- I have searched for duplicate or closed issues.
- I have read the guide for submitting bug reports.
- I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
- I have removed any sensitive information from my code snippets and submission.
How did you install the Amplify CLI?
yarn
If applicable, what version of Node.js are you using?
v16.15.1
Amplify CLI Version
9.2.1
What operating system are you using?
Mac
Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.
None
Amplify Categories
auth, api
Amplify Commands
add
Describe the bug
I set up an api and am using DataStore. The data is not syncing with the cloud.
I get this error message when calling DataStore.clear(), but following the steps in the troubleshooting link did not solve my problem.
[ERROR] 04:34.104 DataStore - Schema is not initialized. DataStore will not function as expected. This could happen if you have multiple versions of DataStore installed. Please see https://docs.amplify.aws/lib/troubleshooting/upgrading/q/platform/js/#check-for-duplicate-versions
I found the function that gives me the error message in the first place as well, checkSchemaInitialized().
https://github.com/aws-amplify/amplify-js/blob/main/packages/datastore/src/datastore/datastore.ts#L236
It fails on the check to see if the schema has been initialized by initSchema().
Other guesses:
Perhaps the bug is the fact that my appId is different than AppSync’s Graphql API appId. The AppSync GraphQL API is created automatically when I do amplify add api
though, so I don’t why it wouldn’t be in sync. Maybe it’s intentional that it uses a different appId. Hope someone can confirm.
I also observed that in aws-exports.js (which I re-generated by deleting and re-running $ amplify pull --appId xxxxxxxx --envName dev
, the aws_appsync_graphqlEndpoint contains what appears to be a different AppSync apiId from the one shown in the AppSync console. For ex, my AppSync’s apiId is “xxx” while I’m seeing "aws_appsync_graphqlEndpoint": "https://yyy.appsync-api.us-east-1.amazonaws.com/graphql"
However, when I download the config in the AppSync page, the values in that config are the same that are inside my aws-exports.js file. So perhaps these are the correct values.
Expected behavior
Expected the DataStore to sync in the cloud, but it’s not sending anything to the DynamoDB tables from my app.
Reproduction steps
- amplify init
- amplify add api (with conflict detection enabled)
- add User table to schema.graphql
- amplify push
- amplify codegen && amplify codegen models
- subscribe to user table in a useEffect
useEffect(() => {
const sub = DataStore.observeQuery(User).subscribe(({ items }) => {
setUsers(items);
});
return () => {
sub.unsubscribe();
};
}, []);
- create a user manually in dynamodb console OR create user from the app (which is in DataStore locally)
- observe no users in the dynamodb console
GraphQL schema(s)
# Put schemas below this line
enum UserRole {
ADMIN
USER
}
type User @model @auth(rules: [{allow: public}]) {
id: ID! @primaryKey
email: String!
username: String
name: String
bio: String
image: String
role: UserRole! @default(value: "USER")
}
Project Identifier
Project Identifier: 6e09cfa89c194655d06e94a2a3ed1fa5
Log output
# Put your logs below this line
[ERROR] 04:34.104 DataStore - Schema is not initialized. DataStore will not function as expected. This could happen if you have multiple versions of DataStore installed. Please see https://docs.amplify.aws/lib/troubleshooting/upgrading/q/platform/js/#check-for-duplicate-versions
Additional information
I’m not using Amplify Studio, just the console. I’ve deleted and re-created my app many times with the same result.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Update: I solved my problem. The issue was because I didn’t run “amplify codegen” and “amplify codegen models” AFTER enabling conflict detection (by running “amplify api update”). Then I had to run amplify push after doing so for everything to be in sync.
I updated the steps to reproduce (and posted my package.json above). Originally I noted this was an issue with DataStore.clear(), but upon performing the steps outlined, this doesn’t seem to be the case. Creating any data locally simply doesn’t sync with the cloud.
Re: “can you watch network activity”, I opened CloudWatch management but I don’t see any errors coming in