Skip to content

Instantly share code, notes, and snippets.

@franzwilding
Created July 24, 2018 14:35
Show Gist options
  • Save franzwilding/aa449bf9f67c6e5da370ed213c3ccfec to your computer and use it in GitHub Desktop.
Save franzwilding/aa449bf9f67c6e5da370ed213c3ccfec to your computer and use it in GitHub Desktop.
# imports ...
// Install vue plugins
Vue.use(VueApollo);
Vue.use(VueMoment);
Vue.use(VueRouter);
// init graphql endpoint
const httpLink = new HttpLink({ uri: process.env.VUE_APP_UNITE_API_ENDPOINT });
// add the authorization to the headers
const authMiddleware = new ApolloLink((operation, forward) => {
operation.setContext(({ headers = {} }) => ({
headers: {
...headers,
authorization: process.env.VUE_APP_UNITE_API_KEY,
}
}));
return forward(operation);
})
// Create apollo client and provider
const apolloClient = new ApolloClient({
link: from([ authMiddleware, httpLink ]),
cache: new InMemoryCache()
});
const apolloProvider = new VueApollo({
defaultClient: apolloClient
});
// Define routes
const router = new VueRouter({
routes: [
{ path: '/', component: ArticleList },
{ path: '/about', component: About },
{ path: '/article/:id', component: ArticleDetails }
]
})
// Init vue app (with the apollo provider)
new Vue({
router: router,
provide: apolloProvider.provide(),
render: h => h(App),
}).$mount('#app')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment