Amplify-js: Datastore sync not working, only locally

Created on 23 Mar 2020  路  6Comments  路  Source: aws-amplify/amplify-js

With this schema I am not able to sync to the cloud.

type Quiz @model @auth(rules: [{ allow: public, provider: iam }]) {
  id: ID!
  title: String!
  subscribers: [Subscribers] @connection(name: "QuizSubscribers")
  resonses: [Responses] @connection(name: "QuizResponses")
  started: Boolean!
}

type Questions @model @auth(rules: [{ allow: public, provider: iam }]) {
  id: ID!
  question: String!
  answers: [Answers] @connection(name: "QuizAnswers")
  resonses: [Responses] @connection(name: "QuestionResponses")
}

type Answers @model @auth(rules: [{ allow: public, provider: iam }]) {
  id: ID!
  answer: String!
  status: Boolean
  question: Questions @connection(name: "QuizAnswers")
}

type Subscribers @model @auth(rules: [{ allow: public, provider: iam }]) {
  id: ID!
  quiz: Quiz @connection(name: "QuizSubscribers")
  name: String!
  score: Int!
  responses: [Responses] @connection(name: "SubscriberResponses")
}

type Responses @model @auth(rules: [{ allow: public, provider: iam }]) {
  id: ID!
  quiz: Quiz @connection(name: "QuizResponses")
  time: String!
  question: Questions @connection(name: "QuestionResponses")
  subscriber: Subscribers @connection(name: "SubscriberResponses")
}

when execute this code

 const subscriber = await DataStore.save(
      new Subscribers({
        name: "ramon",
        score: 0,
        subscribersQuizId: "a123"
      })
    )

the data is added to the local data store but not synced to the cloud, the returned data looks like this (subscribersQuizId: null):
name: "ramon" score: 0 subscribersQuizId: null id: "f5462124-63d6-4a77-9607-2c0e5549a47b" _version: undefined _lastChangedAt: undefined _deleted: undefined

I used the NPX script to generate the API

this is the repo: https://github.com/rpostulart/quizit

DataStore

All 6 comments

Hi @rpostulart

Thank you so much for the repo, it helped a lot when troubleshooting

Looks like DataStore is not being configured automatically (this is a bug)

For now, please do an explicit:

/**
 * Implement Gatsby's Browser APIs in this file.
 *
 * See: https://www.gatsbyjs.org/docs/browser-apis/
 */

// You can delete this file if you're not using it
import Amplify from "@aws-amplify/core"
import {DataStore} from "@aws-amplify/datastore"

import awsConfig from "./src/aws-exports"
Amplify.configure(awsConfig)
DataStore.configure(awsConfig)

@rpostulart I've sent a PR to your repo with the changes I had to make

I hope this helps, I am closing the issue, let us know if you need it re-opened or create a new one

Woehoe, this definitely helps! Now is my serverless online quiz almost ready with 100% datastore!
thx

BTW I keep that repo open for further issues, so we can collaborate on that!

I have landed on the same bug. Fixed it with manual configure like suggested above.

It is confusing having network sync work only when running it on localhost, but then breaking when deployed to amplifyhosting.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rayhaanq picture rayhaanq  路  3Comments

ddemoll picture ddemoll  路  3Comments

DougWoodCDS picture DougWoodCDS  路  3Comments

romainquellec picture romainquellec  路  3Comments

shinnapatthesix picture shinnapatthesix  路  3Comments