4

I am new in Vue 3 and Apollo Composable. I first created a Vuex store and a module service to fetch data from GraphQL endpoint. Furthermore, I noticed during implementation that I can't call useMutation and useQuery outside of setup().

Can I have more explanations about that and also if there are other ways to use useQuery and useMutation outside of setup() can you please show them to me ?

Cedric Achi
  • 78
  • 1
  • 7

1 Answers1

4

Yes. You can use provideApolloClient to get access of it outside of a component. You can do it like this:

import { provideApolloClient } from '@vue/apollo-composable'
import { defaultClient } from '../../vue-apollo';
import { useQuery, useResult, useLazyQuery } from '@vue/apollo-composable'

provideApolloClient(defaultClient)

The import of defaultClient from vue-apollo file is my own file, were I have defined HttpLink and ApolloClient that uses that HttpLink. Feel free to ping me, if you need clarification.