使用nextjs和apollo的SSR无法在生产环境中运行

时间:2019-11-19 09:33:08

标签: apollo next.js react-apollo apollo-client

当前使用

在我的网站上工作

堆栈:NextJS / Apollo客户端/ GraphQL Yoga / Prisma。

在本地计算机上一切正常,但是在将其发布以进行发布时我丢失了SSR。

withData.js:

import withApollo from 'next-with-apollo';
import ApolloClient, { InMemoryCache } from 'apollo-boost';
import { LOCAL_FILTERS_QUERY } from '../apollo/Queries';
import { endpoint, prodEndpoint } from '../config';

const cache = new InMemoryCache();

function createClient({ headers }) {
 return new ApolloClient({
   cache,
   uri: process.env.NODE_ENV === 'development' ? endpoint : prodEndpoint,
   request: operation => {
     operation.setContext({
       fetchOptions: {
         credentials: 'include'
       },
       headers
     });
   },
   resolvers: {
     Query: {},
     Mutation: {}
}
});
}
cache.writeData({
 data: {
   searchFilter: {
     isOpen: false,
     __typename: 'SearchFilter'
   },
   filters: {
     category: '',
     query: '',
     lat: 52.092876,
     lng: 5.10448,
     distance: 500,
     driverLicense: ['B', 'C', 'CE'],
     jobTypes: ['PARTTIME', 'FULLTIME', 'INTERNSHIP', 'SIDEJOB'],
     __typename: 'Filters'
   }
 }
});
export default withApollo(createClient);

我正在使用 nextjs 9.0.3

生产源代码: screenshot

所需情况: Local machine source code

我想这与上下文有关,但是我不知道如何解决这个问题。预先感谢。

0 个答案:

没有答案