gpt4 book ai didi

reactjs - AWS 放大数据存储不会与服务器同步

转载 作者:行者123 更新时间:2023-12-03 19:05:58 25 4
gpt4 key购买 nike

所以我试图让 AWS Amplify 的数据存储库与我正在构建的 reactJS Web 应用程序一起使用。我手动使用graphql突变向api发送数据和从api发送数据就好了,然后我尝试按照this tutorial设置DataStore .在带有索引数据库的客户端中一切正常,但我无法获取与 api 同步的数据。我在控制台中收到以下错误:

 DataStore - Data won't be synchronized. No GraphQL endpoint configured. Did you forget `Amplify.configure(awsconfig)`?
我仔细检查了一遍,我肯定将我的 AWS 导出包括在内:
import Amplify from "@aws-amplify/core";
import awsExports from "./aws-exports";

Amplify.configure(awsExports);
以及生成的内容 ./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;
我已经仔细检查了 aws_appsync_graphqlEndpoint 的凭据和 aws_appsync_apiKey并且它们匹配从 amplify status 返回的值在 cli 中。我也跑了 amplify push我的 Api 的状态为 No Change .在设置 api 时,我确保也启用了冲突解决方案,如教程中所述。
有趣的是,我在设置放大时还尝试了以下操作:
import Amplify from "@aws-amplify/core";
import {DataStore} from "@aws-amplify/datastore";
import awsExports from "./aws-exports";

Amplify.configure(awsExports);
DataStore.configure(awsExports);
这解决了 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
这是否意味着我的 API 没有正确配置?我将如何修复它?

最佳答案

这一定是一个问题,提出了最近的更新。大约一周前,我在 expo 应用程序中成功使用了 DataStore (v2.2.8)。昨天,我开始了一个新的 expo 应用程序项目,但无法找到一种方法来同步启动和运行 DataStore。您是否尝试过旧版本的 @aws-amplify/datastore?

关于reactjs - AWS 放大数据存储不会与服务器同步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63646190/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com