Sam*_*Sam 6 amazon-web-services reactjs aws-amplify aws-amplify-sdk-js
因此,我试图让 AWS Amplify 的数据存储库与我正在构建的 ReactJS Web 应用程序一起使用。我手动使用 graphql 突变向 api 发送数据并从 api 发送数据,然后我尝试按照本教程设置 DataStore 。在具有索引数据库的客户端中,一切工作正常,但我无法使数据与 api 同步。我在控制台中收到以下错误:
DataStore - Data won't be synchronized. No GraphQL endpoint configured. Did you forget `Amplify.configure(awsconfig)`?
Run Code Online (Sandbox Code Playgroud)
我仔细检查了一遍,我肯定将我的 AWS 导出包括在内:
import Amplify from "@aws-amplify/core";
import awsExports from "./aws-exports";
Amplify.configure(awsExports);
Run Code Online (Sandbox Code Playgroud)
生成的内容./aws-exports.js如下:
/* eslint-disable */
// WARNING: DO NOT EDIT. This file is automatically generated by AWS Amplify. It will be overwritten.
const awsmobile = {
"aws_project_region": "us-east-2",
"aws_appsync_graphqlEndpoint": "https://xxxxxxxxxxxxxx.appsync-api.us-east-2.amazonaws.com/graphql",
"aws_appsync_region": "us-east-2",
"aws_appsync_authenticationType": "API_KEY",
"aws_appsync_apiKey": "xxxxxxxxxxxxxx",
"aws_cognito_identity_pool_id": "us-east-2:xxxxxxxxxxxxx",
"aws_cognito_region": "us-east-2",
"aws_user_pools_id": "us-east-2_xxxxxxxxx",
"aws_user_pools_web_client_id": "xxxxxxxxxxxxxxxxxx",
"oauth": {}
};
export default awsmobile;
Run Code Online (Sandbox Code Playgroud)
aws_appsync_graphqlEndpoint我已经仔细检查了和 的凭据,它们与 cliaws_appsync_apiKey返回的值相匹配。amplify status我也运行过amplify push并且我的 Api 的状态为No Change. 设置 api 时,我确保也启用冲突解决,如教程中所指定。
有趣的是,我在设置 amplify 时还尝试了以下操作:
import Amplify from "@aws-amplify/core";
import {DataStore} from "@aws-amplify/datastore";
import awsExports from "./aws-exports";
Amplify.configure(awsExports);
DataStore.configure(awsExports);
Run Code Online (Sandbox Code Playgroud)
这解决了DataStore - Data won't be synchronised错误,但我收到了以下错误,并且数据仍然没有发送到 api。
DataStore - subscriptionError Subscribe only available for AWS AppSync endpoint
DataStore - Sync error Subscribe only available for AWS AppSync endpoint
Run Code Online (Sandbox Code Playgroud)
这是否意味着我的 API 未正确配置?我该如何修复它?
小智 1
这肯定是一个问题,最近更新了。大约一周前,我在一个展会应用程序中成功使用了 DataStore (v2.2.8)。昨天,我启动了一个新的博览会应用程序项目,但无法找到一种方法来启动数据存储并同步运行。您是否尝试过旧版本的@aws-amplify/datastore?
| 归档时间: |
|
| 查看次数: |
9264 次 |
| 最近记录: |