import { ApolloClient , ApolloLink , InMemoryCache , NormalizedCacheObject , } from '@apollo/client' ; import { typePolicies } from './type-policies' ; import generatedIntrospection from '~/graphql/fragment-matcher.generated.json' ; import { isServer } from '~/utils/is-server' ; import { httpLink } from './links/http.link' ; import { createAuthLink } from './links/auth.link' ; import { refreshLink } from './links/refresh.link' ; function createApolloClient ( initialState = { } , serverAccessToken ? ) { return new ApolloClient ( { ssrMode : typeof window === 'undefined' , link : ApolloLink . from ( [ refreshLink , createAuthLink ( serverAccessToken ) , httpLink , ] ) , cache : new InMemoryCache ( { typePolicies , possibleTypes : generatedIntrospection . possibleTypes , } ) . restore ( initialState ) , } ) ; } let apolloClient = null ; export function initApolloClient ( initState ? , serverAccessToken ? ) { if ( isServer ( ) ) { return createApolloClient ( initState , serverAccessToken ) ; } if ( ! apolloClient ) { apolloClient = createApolloClient ( initState ) ; } return apolloClient ; }