如何使用 Amplify DataStore 将数据同步到 AWS DynamoDB?
How to sync data to AWS DynamoDB using Amplify DataStore?
我已经设置了一个 React Amplify 项目。我已经使用 Cognito 用户池成功地让 Auth 工作,但似乎无法弄清楚 DataStore/API。
我目前使用 DataStore 在本地保存数据,但它似乎没有在后端更新。我在 aws-exports.js
中确实有 aws_appsync_graphqlEndpoint
。
不确定如何在 this guide 中启用同步引擎。
您可以使用DataStore.query
查询数据。
DataStore.save
保存记录等
下面的例子应该是很好的起点。
您必须从 @aws-amplify/core
导入 Amplify
并且 NOT 从 aws-amplify
以下代码示例在 App.js 中运行良好,位于所有导入的 BOTTOM:
import Amplify from "@aws-amplify/core";
import { DataStore, Predicates } from "@aws-amplify/datastore";
import { Post, PostStatus } from "./models";
//Use next two lines only if syncing with the cloud
import awsconfig from "./aws-exports";
Amplify.configure(awsconfig);
来源:https://docs.amplify.aws/lib/datastore/examples/q/platform/js
如果我对问题的理解正确,一切都已使用 DataStore 进行设置并在本地运行。问题是它不同步到云。建议使用 Apollo 的答案之一。你不需要阿波罗。默认情况下,建议使用 DataStore 的开发模式仅限于本地。当您准备好部署到云时,您可以使用命令
amplify push
为应用配置所有云资源。有关详细信息,请参阅 DataStore docs。
我已经设置了一个 React Amplify 项目。我已经使用 Cognito 用户池成功地让 Auth 工作,但似乎无法弄清楚 DataStore/API。
我目前使用 DataStore 在本地保存数据,但它似乎没有在后端更新。我在 aws-exports.js
中确实有 aws_appsync_graphqlEndpoint
。
不确定如何在 this guide 中启用同步引擎。
您可以使用DataStore.query
查询数据。
DataStore.save
保存记录等
下面的例子应该是很好的起点。
您必须从 @aws-amplify/core
导入 Amplify
并且 NOT 从 aws-amplify
以下代码示例在 App.js 中运行良好,位于所有导入的 BOTTOM:
import Amplify from "@aws-amplify/core";
import { DataStore, Predicates } from "@aws-amplify/datastore";
import { Post, PostStatus } from "./models";
//Use next two lines only if syncing with the cloud
import awsconfig from "./aws-exports";
Amplify.configure(awsconfig);
来源:https://docs.amplify.aws/lib/datastore/examples/q/platform/js
如果我对问题的理解正确,一切都已使用 DataStore 进行设置并在本地运行。问题是它不同步到云。建议使用 Apollo 的答案之一。你不需要阿波罗。默认情况下,建议使用 DataStore 的开发模式仅限于本地。当您准备好部署到云时,您可以使用命令
amplify push
为应用配置所有云资源。有关详细信息,请参阅 DataStore docs。