import { ApolloClient , HttpLink , InMemoryCache , NormalizedCacheObject , } from '@apollo/client' ; import { setContext } from '@apollo/client/link/context' ; import fetch from 'cross-fetch' ; import config from './config' ; let _authToken ; export function setAuthToken ( token = '' ) { _authToken = token ; const httpLink = new HttpLink ( { fetch , uri : `${ config . signalApi }/` , } ) ; const authLink = setContext ( ( _ , { headers } ) => { const token = _authToken ; return { headers : { ... headers , authorization : token ? `${ token }` : '' , } , } ; } ) ; _client = new ApolloClient ( { link : authLink . concat ( httpLink ) , cache : new InMemoryCache ( { typePolicies : { Query : { fields : { getAttendeeCalendar : { merge ( existing , incoming ) { return [ ... incoming ] ; } , } , } , } , } , } ) , } ) ; } let _client ; setAuthToken ( ) ; export function client ( ) { return _client ; }