1

这是我的代码,我想我完全遵循 next-urql 指令,

import { withUrqlClient } from "next-urql"
import { dedupExchange,cacheExchange,fetchExchange,ssrExchange } from "urql";
// import { cacheExchange } from "@urql/exchange-graphcache";
import { Navbar } from "../components/Navbar"
import { useTodosQuery } from "../generated/graphql";
import { createUrqlClient } from "../utils/createUrqlClient"

const Index = () => {
  const [{data}] = useTodosQuery();
  return(
    <>
    <Navbar/>
    <div>Hello world</div>
    <br></br>
    {!data ? (<div>Loading...</div>): data.todos.map((todo) => <div key={todo.id}>{todo.title}</div>)}
    </>
  )
};

export default withUrqlClient( (ssrExchange:any)=>({
  url:'https://localhost:4000/graphql',
  //for the cookie to workz
  fetchOptions:{
    credentials:"include" 
  },
  //for cache update
  exchanges: [dedupExchange,cacheExchange, ssrExchange, fetchExchange]
}))(Index);

所以事情就是这样,当我不设置 {ssr:true} 时它工作正常,但为了使用服务器端渲染,我必须激活它,之后,我的网站不会向我的网站发送任何请求服务器,所以它无法工作,我想知道这是为什么

4

1 回答 1

0

我认为这是错误:

  url:'https://localhost:4000/graphql',

而不是“https”使用“http”

于 2021-12-20T15:15:53.807 回答