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.13k forks source link

DataStore only keeping a subset of models data #4756

Closed jesper-bylund closed 4 years ago

jesper-bylund commented 4 years ago

Describe the bug I'm setting up a new API based on a complex GraphQL schema, but none of my models seem to work properly.

After some testing I'm findin that only a part of my models are actually being handled my DataStore, the models are being added to DynamoDb, but I cant Get the rest of the model data. With this model I can save changes to DynamoDb, but I can only read or Get the following:

This is the accessible data

id: "ec6a74b3-5a22-4e3c-b1ed-99403076869b"
profileID: "d8063080-abdf-43ab-a882-1f68110a48c0"
postID: "5d387fba-fabd-42a7-bfa3-2896400faa5f"
_version: 7
_lastChangedAt: 1579718521990
_deleted: null

This is the model:

type Location
  @model
  @auth(
    rules: [
      { allow: owner }
      {
        allow: groups
        groups: ["admins"]
        queries: [get, list]
        mutations: [create, update, delete]
      }
      { allow: groups, groups: ["members"], queries: [get, list] }
    ]
  ) {
  id: ID!
  profileID: ID!
  postID: ID!
  city: String!
  country: String!
}

These are the svelte functions I use for testing:

const getLocation = async () => {
    let location = await DataStore.query(Location, c =>
      c.or(c => c.profileID("eq", $user.attributes.sub))
    );
    console.log("Get Entity: ", user, user.city);
  };

  const createLocation = async () => {
    let newLocation = await DataStore.save(
      new Location({
        profileID: $user.attributes.sub,
        postID: uuid.v4(),
        city: "Stockholm",
        country: "Sweden"
      })
    );
    console.log("create entity ", newLocation);
    userProfile = newLocation[0];
  };

  const updateLocation = async () => {
    let location = await DataStore.query(Location, c =>
      c.or(c => c.profileID("eq", $user.attributes.sub))
    );
    console.log("update original entity: ", location);
    var updatedLocation = await DataStore.save(
      Location.copyOf(location[0], updated => {
        updated.city = "Göteborg";
      })
    );
    console.log("update entity ", location, updatedLocation);
  };

This is my package list:

{
    "name": "svelte-app",
    "repository": "https://github.com/raelmiu/champagne-glory",
    "license": "all rights reserved",
    "version": "1.0.0",
    "devDependencies": {
        "@aws-amplify/api": "latest",
        "@aws-amplify/core": "^2.2.2",
        "@aws-amplify/datastore": "^1.0.4",
        "@aws-amplify/pubsub": "^2.1.3",
        "@aws-amplify/storage": "^2.1.3",
        "@beyonk/svelte-carousel": "^2.1.1",
        "@fullhuman/postcss-purgecss": "^1.3.0",
        "autoprefixer": "^9.7.4",
        "aws-appsync": "^3.0.2",
        "cross-env": "^5.2.0",
        "css-loader": "^2.1.1",
        "graphql-tag": "^2.10.1",
        "marked": "^0.7.0",
        "mini-css-extract-plugin": "^0.6.0",
        "npm-run-all": "^4.1.5",
        "postcss": "^7.0.26",
        "postcss-cli": "^6.1.3",
        "postcss-import": "^12.0.1",
        "postcss-loader": "^3.0.0",
        "postcss-preset-env": "^6.7.0",
        "serve": "^11.3.0",
        "sirv-cli": "^0.4.5",
        "style-loader": "^1.1.3",
        "svelte": "^3.17.1",
        "svelte-awesome": "^2.2.1",
        "svelte-loader": "^2.13.6",
        "tailwindcss": "^1.1.4",
        "uuid": "^3.4.0",
        "webpack": "^4.41.5",
        "webpack-cli": "^3.3.10",
        "webpack-dev-server": "^3.10.1",
        "yrv": "0.0.16",
        "ini": "^1.3.5",
        "inquirer": "^6.5.1"
    },
    "dependencies": {
        "date-fns": "^2.9.0"
    },
    "scripts": {
        "dev": "run-p webpack && watch:tailwind",
        "build": "cross-env NODE_ENV=production webpack",
        "start": "sirv public --single",
        "start:dev": "sirv public --single --dev",
        "webpack": "webpack-dev-server --content-base public",
        "watch:tailwind": "postcss src/main.css -o public/index.css -w",
        "build:tailwind": "NODE_ENV=production postcss src/main.css -o public/index.css",
        "amplify-modelgen": "node amplify/scripts/amplify-modelgen.js",
        "amplify-push": "node amplify/scripts/amplify-push.js"
    }
}
jesper-bylund commented 4 years ago

After extensive testing this turns out to be a mismatch between an amplify-cli version and DataStore v1.0.4. I'm afraid I don't have any way of finding out which CLI version it was. But updating CLI solved the issue, and future reports of the same issue will look like DataStore locally storing only a partial model.

github-actions[bot] commented 3 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.