INNER CODE UNIT · TypeScript
createApolloClient
panaverse/learn-nextjs · nextjs12/step21_fetching_data_csr_graphql_extra/lib/apollo/index.ts:15
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;