Skip to content

Instantly share code, notes, and snippets.

@michal-wrzosek
Created November 21, 2019 19:58
Show Gist options
  • Save michal-wrzosek/eebee0e5dfbdc45cbad8f1c237ca777f to your computer and use it in GitHub Desktop.
Save michal-wrzosek/eebee0e5dfbdc45cbad8f1c237ca777f to your computer and use it in GitHub Desktop.
Next.js + Apollo - _app page
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