mirror of
https://github.com/apotdevin/thunderhub.git
synced 2025-02-22 22:25:21 +01:00
27 lines
815 B
TypeScript
27 lines
815 B
TypeScript
import { ApolloClient, InMemoryCache, HttpLink } from 'apollo-boost';
|
|
import fetch from 'isomorphic-unfetch';
|
|
import withApollo from 'next-with-apollo';
|
|
import getConfig from 'next/config';
|
|
|
|
const { publicRuntimeConfig } = getConfig();
|
|
const { apiUrl } = publicRuntimeConfig;
|
|
|
|
const link = new HttpLink({
|
|
uri: apiUrl,
|
|
credentials: 'same-origin',
|
|
fetch,
|
|
});
|
|
|
|
// Export a HOC from next-with-apollo
|
|
// Docs: https://www.npmjs.com/package/next-with-apollo
|
|
export default withApollo(
|
|
// You can get headers and ctx (context) from the callback params
|
|
// e.g. ({ headers, ctx, initialState })
|
|
({ initialState }) =>
|
|
new ApolloClient({
|
|
link,
|
|
cache: new InMemoryCache()
|
|
// rehydrate the cache using the initial data passed from the server:
|
|
.restore(initialState || {}),
|
|
})
|
|
);
|