【问题标题】:AWS Amplify Datastore AppSync not synchronize IndexDB with DynamoDBAWS Amplify Datastore AppSync 未将 IndexDB 与 DynamoDB 同步
【发布时间】:2021-05-24 15:56:06
【问题描述】:

我关注了this tutorial。在我将 aws-amplify 更新到 v3.3.26 之前它工作得很好。更新后它停止将 IndexDB 与 DynamoDB 同步。我设置Amplify.Logger.LOG_LEVEL = 'DEBUG'时没有任何错误。

main.ts 的教程之后我有:

import Amplify from "@aws-amplify/core";
import {DataStore} from "@aws-amplify/datastore";
import awsExports from "./aws-exports";

Amplify.configure(awsExports);

之后,我从 Amplify UI 中提取数据,生成了 GraphQl 模型和 src/aws-exports.js

const awsmobile = {
    "aws_project_region": "REGION",
    "aws_appsync_graphqlEndpoint": "https://xxxxxxxxxxx.appsync-api.REGION.amazonaws.com/graphql",
    "aws_appsync_region": "REGION",
    "aws_appsync_authenticationType": "API_KEY",
    "aws_appsync_apiKey": "xxx-xxxxxxxxxxxxxxxxxx",
    "aws_cognito_identity_pool_id": "REGION:xxxxx-xxxxxx-xxxxx-xxxxxxx-xxxxxxx",
    "aws_cognito_region": "REGION",
    "aws_user_pools_id": "REGION_xxxxxxxx",
    "aws_user_pools_web_client_id": "xxxxxxxxxxxxxxxxx",
    "oauth": {},
    "aws_content_delivery_bucket": "BUCKET",
    "aws_content_delivery_bucket_region": "us-east-2",
    "aws_content_delivery_url": "http://BUCKET.s3-website.REGION.amazonaws.com"
};```

And I tried to update data like this:

等待 DataStore.save(User.copyOf(data, (item:MutableModel) => { 项目.电话=数据.电话; }));```

【问题讨论】:

    标签: angular amazon-web-services aws-amplify aws-amplify-sdk-js


    【解决方案1】:

    为了修复它,我将main.ts 更改为:

    src/main.ts

    import awsconfig from './aws-exports'
    import PubSub from '@aws-amplify/pubsub';
    import API from '@aws-amplify/api';
    import Amplify, { Logger } from 'aws-amplify';
    import {DataStore} from '@aws-amplify/datastore';
    
    API.configure(awsconfig);
    PubSub.configure(awsconfig);
    Amplify.configure(awsconfig);
    DataStore.configure(awsconfig);
    Logger.LOG_LEVEL = 'ERROR';
    DataStore.start();
    

    现在我需要在编辑数据时订阅模型更改。

    src/app/user/edit-user.component.ts

    import {DataStore} from '@aws-amplify/datastore';
    import {User} from '../models';
    
    
    @Component({
      selector: 'app-edit-page',
      templateUrl: './edit-page.component.html',
      styleUrls: ['./edit-page.component.scss']
    })
    export class EditPageComponent implements OnInit {
      subscription;
    
      ngOnInit() {
        this.subscription = DataStore.observe<User>(User).subscribe(() => {});
      }
      async update(data) {
        await DataStore.save(User.copyOf(data, (item:MutableModel<User>) => {
          item.phone = data.phone;
        }));
      }
      ngOnDestroy() {
        if (this.subscription) this.subscription.unsubscribe();
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2022-12-14
      • 2019-10-19
      • 2022-12-06
      • 2018-10-27
      • 1970-01-01
      • 2020-08-30
      • 2020-11-18
      • 2018-08-19
      • 2021-05-08
      相关资源
      最近更新 更多