Created
December 3, 2018 04:26
-
-
Save meshboy/69bdcca49aeaa1811393699a708e261d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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