Repository URL to install this package:
|
Version:
0.3.0 ▾
|
import { ApolloClient, ApolloClientOptions } from 'apollo-client'
import { ApolloLink } from 'apollo-link'
import cache from './cache/apolloCache'
const IS_BROWSER = typeof window === 'object'
export interface CreateApolloClientOptions {
link: ApolloLink
}
/**
* @example
* import { createApolloClient, consoleLink, errorLink, httpLink, persistCache } from 'create-apollo-client'
* // create your own stateLink if you want, put it before httpLink
* const link = ApolloLink.from([consoleLink, errorLink, stateLink, httpLink])
* export const { client, cache } = createApolloClient({ link })
* // use client side query persistance, note, this is slow
* persistCache()
*/
function createApolloClient(options: CreateApolloClientOptions) {
/**
* @note can also export this top level to be mutated...
*/
const clientConfig: ApolloClientOptions<any> = {
link: options.link,
cache,
ssrMode: IS_BROWSER === false,
connectToDevTools: IS_BROWSER === true,
ssrForceFetchDelay: IS_BROWSER ? 100 : undefined,
}
const client = new ApolloClient(clientConfig)
return client
}
export { createApolloClient }