2018-11-27 10:51:33 +00:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2018-12-18 14:43:23 +00:00
|
|
|
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';
|
2018-11-26 15:57:11 +00:00
|
|
|
|
2018-11-27 13:14:10 +00:00
|
|
|
// Satellite url
|
2018-11-26 15:57:11 +00:00
|
|
|
const satelliteUrl = new HttpLink({
|
2018-12-18 14:43:23 +00:00
|
|
|
uri: 'http://localhost:8081/api/graphql/v0',
|
2018-11-26 15:57:11 +00:00
|
|
|
});
|
|
|
|
|
2018-11-27 13:14:10 +00:00
|
|
|
// Adding auth headers
|
2018-12-18 14:43:23 +00:00
|
|
|
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}` : '',
|
|
|
|
}
|
|
|
|
};
|
2018-11-27 13:14:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Creating apollo client
|
2018-11-27 10:51:33 +00:00
|
|
|
export default new ApolloClient({
|
2018-12-18 14:43:23 +00:00
|
|
|
link: authLink.concat(satelliteUrl),
|
|
|
|
cache: new InMemoryCache(),
|
|
|
|
connectToDevTools: true,
|
|
|
|
});
|