I'm using Next.js 9.3.5 with Apollo and GraphQL for an SSR project I'm working on. I've implemented this example provided in the official pages:
https://github.com/vercel/next.js/blob/canary/examples/with-apollo/lib/apollo.js
So my page looks like this:
import { withApollo } from '../apollo/withApollo';
const Collections = (props) => {
// ...
}
export const getServerSideProps = async ({ apolloClient }) => {
console.log(apolloClient); // returns undefined
return {
props: {},
};
};
export default withApollo()(Collections);
Problem is that apolloClient
is not available inside getServerSideProps
. But if I use getInitialProps
, then it's working. The official Next.js doc says that we should be using getServerSideProps
.
If you're using Next.js 9.3 or newer, we recommend that you use getStaticProps or getServerSideProps instead of getInitialProps.
Any ideas?
apolloClient
to NextPageContext and NextAppContext? - DedaDevcontext
object by default doesn't haveapolloClient
prop, take look at this github.com/vercel/next.js/issues/9542#issuecomment-592187560 - DedaDevgetInitialProps
withgetServerSideProps
insidewithApollo
, but can't do that either:getServerSideProps can not be attached to a page's component
- Norbert