Apollo graphql
-
Hello,
I’m trying to use vue-apollo with composition API and in docs it says that I should add this code to root file but there isn’t one.Where exactly should I place it?
import { provide } from '@vue/composition-api' import { DefaultApolloClient } from '@vue/apollo-composable' const app = new Vue({ setup () { provide(DefaultApolloClient, apolloClient) }, render: h => h(App), })
Docs url: https://v4.apollo.vuejs.org/guide-composable/setup.html#_1-install-vue-apollo-composable
-
@nededa Try putting it in App.vue
-
Yes it worked, thanks.
-
@nededa could you pls provide details, maybe your App.vue code?
i’m still having issues with that
-
@vasya sure, hope it helps.
<template> <div id="q-app"> <router-view /> </div> </template> <script lang="ts"> import { defineComponent, provide } from '@vue/composition-api'; import { DefaultApolloClient } from '@vue/apollo-composable' import ApolloClient from 'apollo-boost' const apolloClient = new ApolloClient({ uri: 'http://127.0.0.1/graphql' }) export default defineComponent({ name: 'App', setup () { provide(DefaultApolloClient, apolloClient) }, }); </script>
-
Just know, apollo-boost is no longer valid for working with Apollo Client. You should be getting it from
@apollo/client/core
.Scott
-
@s-molinari but why is this still in a docs? https://apollo.vuejs.org/guide/installation.html#_1-apollo-client
-
Because those docs are for Version 3 of of vue-apollo @nededa . https://v4.apollo.vuejs.org/guide/installation.html#vue-cli-plugin
Scott