question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DataStore not syncing on new project

See original GitHub issue

Before 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

  1. amplify init
  2. amplify add api (with conflict detection enabled)
  3. add User table to schema.graphql
  4. amplify push
  5. amplify codegen && amplify codegen models
  6. subscribe to user table in a useEffect
  useEffect(() => {
    const sub = DataStore.observeQuery(User).subscribe(({ items }) => {
      setUsers(items);
    });

    return () => {
      sub.unsubscribe();
    };
  }, []);
  1. create a user manually in dynamodb console OR create user from the app (which is in DataStore locally)
  2. 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

report-1660811631676.zip

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:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
justinjaegercommented, Aug 20, 2022

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.

0reactions
justinjaegercommented, Aug 19, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

AWS amplify datastore wont synchronise with server
I get the following error in the console: DataStore - Data won't be synchronized. No GraphQL endpoint configured.
Read more >
DataStore - Syncing data to cloud - JavaScript - Amplify Docs
Learn more about how DataStore connects to an AppSync backend and automatically syncs all locally saved data using GraphQL. - JavaScript - AWS...
Read more >
Offline-first with DataStore - Amplify for web Immersion Day
We can solve this problem by leveraging an additional feature of DataStore: selective sync. By default, DataStore downloads the entire contents of your...
Read more >
Connect Amplify DataStore with existing SQL datasources
The database is only accessible from a VPC, and does not allow ... I introduce two new Delta Sync tables, one for each...
Read more >
DataStore - CRUD (Create Read Update Delete)
Offline data & cloud sync​. There is no need to write additional code to send a request to the server after the application...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found