INNER CODE UNIT · TypeScript
createApolloClient
panaverse/learn-nextjs · nextjs12/step19_fetching_data_ssr_graphql_extra/lib/apollo/index.ts:16
function createApolloClient() {
return new ApolloClient({
ssrMode: typeof window === 'undefined',
link: new HttpLink({ uri }),
cache: new InMemoryCache(),
});
}
export function initApollo(initialState?: NormalizedCacheObject) {
const client = apolloClient || createApolloClient();
if (initialState != undefined) {
client.cache.restore({
...client.extract(),
...initialState
});
}
if (typeof window === "undefined") {
return client;