Skip to content

Instantly share code, notes, and snippets.

@sockol
Last active September 24, 2019 18:11
Show Gist options
  • Save sockol/8d755f66a5f2a6474d41f2193a944e8f to your computer and use it in GitHub Desktop.
Save sockol/8d755f66a5f2a6474d41f2193a944e8f to your computer and use it in GitHub Desktop.
Get GraphQL Apollo to work with NextJS Server Side Rendering within Docker
import {
ApolloClient,
ApolloLink,
InMemoryCache,
HttpLink,
} from 'apollo-boost'
const isServer = () => typeof window === `undefined`
const create = (initialState = {}, cookies) => {
/* your middleware code here */
const adjustedUri = !isServer() && process.env.NODE_ENV === `development` ? process.env.API_URI_DOCKER : process.env.API_URI
const httpLink = new HttpLink({
uri: `${adjustedUri}/graphql`,
})
return new ApolloClient({
connectToDevTools: process.browser,
ssrMode: !process.browser,
link: httpLink,
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment