Next.js Apollo客户端状态预设缓存在服务器端渲染上不工作

Next.js Apollo客户端状态预设缓存在服务器端渲染上不工作,next.js,react-apollo,apollo-client,server-side-rendering,react-ssr,Next.js,React Apollo,Apollo Client,Server Side Rendering,React Ssr,我正在尝试将Apollo客户端状态数据与钩子useQuery和useMutation一起用作NextJS应用程序中的全局存储。 当我使用apollo()遵循NextJS中名为的示例时,它使用一个HOC,在其中运行所有查询并首先在服务器上呈现应用程序 通常,您希望捕获组件中的“加载”状态,如下所示: const { loading, data } = useQuery(GET_NAME_QUERY) // some @client query if (loading) return <p&g

我正在尝试将Apollo客户端状态数据与钩子
useQuery
useMutation
一起用作NextJS应用程序中的全局存储。 当我使用apollo()遵循NextJS中名为
的示例时,它使用一个HOC,在其中运行所有查询并首先在服务器上呈现应用程序

通常,您希望捕获组件中的“加载”状态,如下所示:

const { loading, data } = useQuery(GET_NAME_QUERY) // some @client query
if (loading) return <p>Loading...</p>
return <h1>Hello {data.name</h1>
const cache = new InMemoryCache().restore(initialState);

// This is the part where the initial client-state data is set:
cache.writeData({
  data: { name: 'Harry' } 
});

const apolloClient =  new ApolloClient({
  cache,  // <-- cache with preset client-state data
  typeDefs,
  resolvers,
})
const{loading,data}=useQuery(GET\u NAME\u QUERY)//some@client QUERY
如果(加载)返回加载

返回Hello{data.name
但是我想跳过加载检查,并始终保持默认状态可用。我认为这可以通过将apollo客户端的缓存设置为一组默认值来实现,如下所示:

const { loading, data } = useQuery(GET_NAME_QUERY) // some @client query
if (loading) return <p>Loading...</p>
return <h1>Hello {data.name</h1>
const cache = new InMemoryCache().restore(initialState);

// This is the part where the initial client-state data is set:
cache.writeData({
  data: { name: 'Harry' } 
});

const apolloClient =  new ApolloClient({
  cache,  // <-- cache with preset client-state data
  typeDefs,
  resolvers,
})
const cache=new InMemoryCache().restore(initialState);
//这是设置初始客户端状态数据的部分:
cache.writeData({
数据:{name:'Harry'}
});
const Apollo客户端=新Apollo客户端({

cache,//似乎有更多的人出现此问题,这可能是
react apollo
中的错误/功能:似乎有更多的人出现此问题,这可能是
react apollo
中的错误/功能: