storj/web/satellite/src/utils/apolloManager.ts
Bogdan Artemenko 6f931759a6
Satellite Web store test coverage (#948)
* Added 100% test coverage for Users store module.

* Added 100% coverage for Projects store module.

* Added 100% coverage for ProjectMembers store module.
2019-01-08 17:14:00 +02:00

36 lines
926 B
TypeScript

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
import { HttpLink } from 'apollo-link-http';
import ApolloClient from 'apollo-client/ApolloClient';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { setContext } from 'apollo-link-context';
import { getToken } from '@/utils/tokenManager';
// Satellite url
const satelliteUrl = new HttpLink({
uri: 'http://localhost:8081/api/graphql/v0',
});
// Adding auth headers
const authLink = setContext((_, {headers}) => {
// get the authentication token from local storage if it exists
const token = getToken();
// return the headers to the context so httpLink can read them
return {
headers: {
...headers,
authorization: token ? `Bearer ${token}` : '',
}
};
});
// Creating apollo client
export default new ApolloClient({
link: authLink.concat(satelliteUrl),
cache: new InMemoryCache(),
connectToDevTools: true,
});