Last active
September 24, 2019 18:11
-
-
Save sockol/8d755f66a5f2a6474d41f2193a944e8f to your computer and use it in GitHub Desktop.
Get GraphQL Apollo to work with NextJS Server Side Rendering within Docker
This file contains hidden or 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 { | |
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