import { ApolloProvider } from '@apollo/react-hooks'; import { InMemoryCache } from 'apollo-cache-inmemory'; import { ApolloClient } from 'apollo-client'; import { createUploadLink } from 'apollo-upload-client'; import { stylesGlobal, stylesGlobalTheme } from 'device-agnostic-ui'; import Head from 'next/head'; const createApolloClient = (cache = {}) => new ApolloClient({ ssrMode: typeof window !== 'undefined', cache: new InMemoryCache().restore(cache), link: createUploadLink({ uri: process.env.API_URI }), }); const App = ({ Component, pageProps, apolloCache, apolloClient = createApolloClient(apolloCache), }) => ( ); App.getInitialProps = async (context) => { const props = { pageProps: context.Component.getInitialProps ? await context.Component.getInitialProps(context) : {}, }; if (context.ctx.req) { const apolloClient = createApolloClient(); try { const { getDataFromTree } = await import('@apollo/react-ssr'); await getDataFromTree( ); } catch (error) { // Prevent crash from GraphQL errors. console.error(error); } Head.rewind(); props.apolloCache = apolloClient.cache.extract(); } return props; }; export default App;