Skip to content

Instantly share code, notes, and snippets.

@meshboy
Created December 3, 2018 04:26
Show Gist options
  • Save meshboy/69bdcca49aeaa1811393699a708e261d to your computer and use it in GitHub Desktop.
Save meshboy/69bdcca49aeaa1811393699a708e261d to your computer and use it in GitHub Desktop.
import Vue from 'vue';
import VueApollo from "vue-apollo";
import apolloUploadClient from "apollo-upload-client"
import { InMemoryCache } from "apollo-cache-inmemory";
import { ApolloClient } from "apollo-client";
import { setContext } from "apollo-link-context";
Vue.use(VueApollo);
const baseUrl = "http://localhost:3000/recipe";
const uploadClientLink = apolloUploadClient.createUploadLink({
uri: baseUrl
});
const interceptor = setContext((request, previousContext) => {
const token = localStorage.getItem("token");
if(token) {
return {
headers: {
authorization: token
}
};
}
});
const apolloClient = new ApolloClient({
link: interceptor.concat(uploadClientLink),
cache: new InMemoryCache(),
connectToDevTools: true
});
const instance = new VueApollo({
defaultClient: apolloClient
});
export default instance;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment