quasarframework / app-extension-apollo

The official Quasar App-Extension for Apollo and GraphQL - Currently Beta!
https://quasar.dev
109 stars 19 forks source link

Error: Apollo client with id default not found. Use provideApolloClient() if you are outside of a component setup, in the q-dialog (modal) #128

Closed ricar2ce closed 1 year ago

ricar2ce commented 1 year ago

Hello, i am getting "Error: Apollo client with id default not found. Use provideApolloClient() if you are outside of a component setup" when i make use of extension inside q-dialog (modal) component. I have made sure that my apollo boot file is register in quasar.conf.js, and any other needed config and the extension works perfectly outside of q-dialog.

I temporarily had to recreate a whole client inside the component,

import { ApolloClient , createHttpLink, InMemoryCache  } from '@apollo/client/core'
import { provideApolloClient} from '@vue/apollo-composable'

const apolloClient = new ApolloClient({
  link: createHttpLink({
    uri:'http://localhost:5000/graphql',
  }),
  cache: new InMemoryCache(),
})

provideApolloClient(apolloClient);

export default {
  name: ...

but it doesn't seem like an optimal solution.

any other ideas to fix this? thanks in advance

smolinari commented 1 year ago

I haven't tried it myself, but did you try putting provideApolloClient inside the boot file after the client is initialized?

Scott

ricar2ce commented 1 year ago

I haven't tried it myself, but did you try putting provideApolloClient inside the boot file after the client is initialized?

Scott

this is my apollo boot file:

...
import { getClientOptions } from 'src/apollo'
export default boot(
 ({ app }) => {
    // Default client.
    const options = /* await */ getClientOptions(/* {app, router ...} */)
    const apolloClient = new ApolloClient(options)

    const apolloClients = {
      default: apolloClient,
    }
    app.provide(ApolloClients, apolloClients)
  }
)
smolinari commented 1 year ago

Yes, try adding provideApolloClient inside the boot method.

Scott