reactjs - AWS Amplify Amplify.configure(awsconfig) 错误
问题描述
我在 NextJs 应用程序中使用了放大 cli。我觉得也许我配置了一些错误我在尝试查询数据时收到此错误:
[警告] 32:17.454 DataStore - 数据不会同步。未配置 GraphQL 端点。你忘记了Amplify.configure(awsconfig)
吗?
但我确实有一个 aws-exports.js 文件。但我确实看到它是 awsmobile ,我不确定我可能做错了什么。
aws 导出文件:
const awsmobile = {
aws_project_region: 'us-east-2',
aws_appsync_graphqlEndpoint:
private,
aws_appsync_region: 'us-east-2',
aws_appsync_authenticationType: 'API_KEY',
aws_appsync_apiKey:private,
}
解决方案
正如警告所暗示的,您可能需要检查是否Amplify.configure(awsconfig)
调用了在项目中设置库。
例如,这是官方文档中给出的示例。
// pages/index.js
import { AmplifyAuthenticator } from "@aws-amplify/ui-react";
import { Amplify, API, Auth, withSSRContext } from "aws-amplify";
import Head from "next/head";
import awsExports from "../src/aws-exports";
import { createPost } from "../src/graphql/mutations";
import { listPosts } from "../src/graphql/queries";
import styles from "../styles/Home.module.css";
Amplify.configure({ ...awsExports, ssr: true });
在您的情况下,您可以awsmobile
从应用程序的入口点导入aws-exports.js
和调用Amplify.configure({...awsmobile, ssr: true});
。
推荐阅读
- c++ - 模板专业化 Clang 10.0
- android - recyclerview 项目大小与布局中的大小不同
- java - 使用 Spring Security 时,Tomcat 访问日志中缺少用户 (%u)
- java - 如何使 BoxLayout 正确左对齐?
- python - 使用机器学习算法从python中的两个列表中查找最短点
- css - 为什么我的外部 CSS 链接在加载时是 404?
- python - 如何在边界内将文本写入 PDF?- Python
- google-tag-manager - 如何选择数据层中数组的最后一个成员?
- c++ - 如何让我的 m_refcount 变量打印出我想要的值而不是垃圾?
- elasticsearch - Elasticsearch:匹配和过滤器中的术语有什么区别?