import { ApolloClient } from 'apollo-client'; import { createHttpLink } from 'apollo-link-http'; import { setContext } from 'apollo-link-context'; import { InMemoryCache } from 'apollo-cache-inmemory'; import { TokenService } from "@Global/services/storage.services"; const httpLink = createHttpLink({ uri: '/graphql', }); const authLink = setContext((_, { headers }) => { // return the headers to the context so httpLink can read them return { headers: { ...headers, authorization: TokenService.getToken() ? `Bearer ${TokenService.getToken()}` : "", } } }); export default new ApolloClient({ link: authLink.concat(httpLink), cache: new InMemoryCache() });