You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
willaengine/resources/js/Global/utils/api/init/apollo.js

27 lines
695 B

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),
5 years ago
cache: new InMemoryCache(),
});