Hello there! I am diving into the world of apollo and graphql, specifically interested in SSR/SSG. While I have a basic understanding of what SSR/SSG entails, implementing it with apollo-client is a bit tricky for me.
After some extensive searching online, I found conflicting information on the correct approach to take. My aim with this post is to clarify the upsides/downsides of two different methods:
// Method 1
const client = new ApolloClient({
link: new HttpLink({ uri: '/graphql' }),
cache: new InMemoryCache(),
});
// Component code using getServerSideProps
// Method 2
const createClient = () => new ApolloClient({
link: new HttpLink({ uri: '/graphql' }),
cache: new InMemoryCache(),
ssrMode: typeof window === 'undefined',
});
// Component code using custom hook useApollo
My confusion lies in whether the second method (with SSR) involves unnecessary repetition of queries and extra coding compared to the first method. What are the performance benefits and safety implications of each?
Thank you for your insights!