Created
November 21, 2019 19:58
-
-
Save michal-wrzosek/eebee0e5dfbdc45cbad8f1c237ca777f to your computer and use it in GitHub Desktop.
Next.js + Apollo - _app page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import App from 'next/app'; | |
import { ApolloProvider } from '@apollo/react-hooks'; | |
import { ApolloClient } from 'apollo-boost'; | |
import getConfig from 'next/config'; | |
import withApollo from 'src/lib/withApollo'; | |
import { GlobalStyles } from 'src/styles/GlobalStyles'; | |
const { publicRuntimeConfig } = getConfig(); | |
const { GRAPHQL_URL_SERVER, GRAPHQL_URL_CLIENT } = publicRuntimeConfig; | |
const isServer = () => typeof window === 'undefined'; | |
const GRAPHQL_URL = isServer() ? GRAPHQL_URL_SERVER : GRAPHQL_URL_CLIENT; | |
export interface MyAppProps { | |
apollo: ApolloClient<any>; | |
} | |
class MyApp extends App<MyAppProps> { | |
render() { | |
const { Component, pageProps, apollo } = this.props; | |
return ( | |
<ApolloProvider client={apollo}> | |
<> | |
<GlobalStyles /> | |
<Component {...pageProps} /> | |
</> | |
</ApolloProvider> | |
); | |
} | |
} | |
export default withApollo(GRAPHQL_URL)(MyApp); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment