2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-11-27 10:51:33 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2018-12-18 14:43:23 +00:00
|
|
|
import { InMemoryCache } from 'apollo-cache-inmemory';
|
2019-09-09 11:33:39 +01:00
|
|
|
import ApolloClient from 'apollo-client/ApolloClient';
|
2018-12-18 14:43:23 +00:00
|
|
|
import { setContext } from 'apollo-link-context';
|
2019-09-09 11:33:39 +01:00
|
|
|
import { HttpLink } from 'apollo-link-http';
|
|
|
|
|
2019-07-22 10:46:26 +01:00
|
|
|
import { AuthToken } from '@/utils/authToken';
|
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({
|
2019-08-20 14:31:01 +01:00
|
|
|
uri: process.env.VUE_APP_ENDPOINT_URL,
|
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}) => {
|
2019-02-20 13:33:56 +00:00
|
|
|
// get the authentication token from local storage if it exists
|
2019-07-22 10:46:26 +01:00
|
|
|
const token = AuthToken.get();
|
2018-12-18 14:43:23 +00:00
|
|
|
|
2019-07-22 10:46:26 +01:00
|
|
|
// return the headers to the context so httpLink can read them
|
2019-02-20 13:33:56 +00:00
|
|
|
return {
|
|
|
|
headers: {
|
|
|
|
...headers,
|
|
|
|
authorization: token ? `Bearer ${token}` : '',
|
2019-09-13 15:58:18 +01:00
|
|
|
},
|
2019-02-20 13:33:56 +00:00
|
|
|
};
|
2018-11-27 13:14:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Creating apollo client
|
2018-11-27 10:51:33 +00:00
|
|
|
export default new ApolloClient({
|
2019-02-20 13:33:56 +00:00
|
|
|
link: authLink.concat(satelliteUrl),
|
|
|
|
cache: new InMemoryCache(),
|
|
|
|
connectToDevTools: true,
|
2018-12-18 14:43:23 +00:00
|
|
|
});
|