所以我试图让 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)`?
我仔细检查了一遍,我肯定将我的 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 配置不正确?我将如何解决它?