我对Next.js和Amp;GraphQL是新手,需要在一个项目上使用两者.因此,try 使用Next.js(JavaScript,Reaction)、Apollo客户端、Apollo服务器来设置一个虚拟项目.服务器端已顺利启动并运行.但是客户端无法在UI中加载Apollo服务器数据,我可以从客户端创建一个基本的API调用并加载数据,但不能使用ApolloProvider
/ApolloWrapper
进行渲染.
我试着关注了网上的许多文章,但都没有奏效.最后一个看起来很有前途,很容易,但却是为TypeScrip-Medium Article和Amp;Repo编写的.我试着跟随它,但仍然不能理解错误:
100
import { Inter } from "next/font/google";
import "./globals.css";
import { ApolloProvider } from "@apollo/client";
// import { ApolloWrapper } from "../lib/apollo-wrapper";
import client from "../lib/client";
const inter = Inter({ subsets: ["latin"] });
export const metadata = {
title: "Create Next App",
description: "Generated by create next app",
};
export default function RootLayout({ children }) {
return (
<html lang="en">
<body className={inter.className}>
<ApolloProvider client={client}>{children}</ApolloProvider>
</body>
</html>
);
}
100
import { ApolloClient, HttpLink, InMemoryCache, from } from "@apollo/client";
const httpLink = new HttpLink({
uri: '/'
})
const client = new ApolloClient({
cache: new InMemoryCache(),
uri: "http://localhost:4000/",
link: from([httpLink])
});
export default client;
100
"dependencies": {
"@apollo/client": "^3.9.0-rc.1",
"@apollo/experimental-nextjs-app-support": "^0.8.0",
"graphql": "^16.8.1",
"next": "14.1.0",
"react": "^18",
"react-dom": "^18"
},
"devDependencies": {
"autoprefixer": "^10.0.1",
"eslint": "^8",
"eslint-config-next": "14.1.0",
"postcss": "^8",
"tailwindcss": "^3.3.0"
}