I'm currently learning NextJS + Apollo and I've been stuck on a problem. Since getInitialProps
is not recommended I'm using getServerSideProps
. Here I'm using this code in order to get the props server-side and populate the components:
export async function getServerSideProps() {
// eslint-disable-next-line no-debugger
const apolloClient = initializeApollo();
await apolloClient.query({
query: GET_BANNER_DATA,
});
return addApolloState(apolloClient, {
props: {},
});
}
The problem is that getServerSideProps
can be used only on pages level and not components. So, I'll have to get props for all the components I use on this page.
How can I do that? Does apolloClient.query
accept more than one query? Or should I do something to addApolloState
function?
The official docs haven't considered this and I couldn't find anything like this on another open-source project.