Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for app.vue or global setup in nuxt bridge #222

Closed
stephenjason89 opened this issue Oct 14, 2021 · 2 comments · Fixed by nuxt/framework#2408
Closed

add support for app.vue or global setup in nuxt bridge #222

stephenjason89 opened this issue Oct 14, 2021 · 2 comments · Fixed by nuxt/framework#2408
Assignees
Labels
bridge enhancement New feature or request

Comments

@stephenjason89
Copy link

Environment

Nuxt CLI v3.0.0-27234347.3759926


Describe the bug

I need to use onGlobalSetup to use vue apollo graphql composables
like this

import { provide, onGlobalSetup, defineNuxtPlugin } from '@nuxtjs/composition-api'
import { DefaultApolloClient } from '@vue/apollo-composable'

export default defineNuxtPlugin(({ app }) => {
    onGlobalSetup(() => {
        provide(DefaultApolloClient, app.apolloProvider?.defaultClient)
    })
})

But it seems like onGlobalSetup is missing.

Thank you

Reproduction

import { provide, onGlobalSetup, defineNuxtPlugin } from '@nuxtjs/composition-api'

what is the counterpart of this on nuxt bridge?

Thanks

Additional context

No response

Logs

No response

@stephenjason89 stephenjason89 added bridge bug Something isn't working labels Oct 14, 2021
@danielroe danielroe reopened this Oct 14, 2021
@tobiasdiez
Copy link
Contributor

According to
https://github.com/nuxt/framework/blob/2a0afbd09296cd65d30c5ef5a5324d64149bc3fe/packages/bridge/src/runtime/capi.legacy.mjs#L130-L134
onGlobalSetup is deprecated now. I'm not sure if I understand the deprecation message correctly, but it seems the following code should do the trick:

export default defineNuxtPlugin(({ app }) => {
    app.provide(DefaultApolloClient, app.apolloProvider?.defaultClient)
})

But that doesn't seem to work as nuxt.provide has a string as the first argument. I had success with

import { provideApolloClient } from '@vue/apollo-composable'
export default defineNuxtPlugin((app) => {
  provideApolloClient(app.apolloProvider?.defaultClient)
})

@stephenjason89
Copy link
Author

stephenjason89 commented Oct 14, 2021

@tobiasdiez Thank you for the quick response.
I am having a webpack error related to this plugin and cannot fully test if it is working on my end yet.

image

here is the screenshot of the error i am having.

Please let me know if you already encountered this issue.

I will be searching for a solution as well :D

Here is the apollo-composable.ts file

image

However, I can confirm that the solution you provide isn't working without the bridge.
I am getting this error without the bridge using your setup for the plugin
image

@danielroe danielroe added enhancement New feature or request and removed bug Something isn't working labels Nov 19, 2021
@danielroe danielroe changed the title nuxt bridge onGlobalSetup add support for app.vue or global setup in nuxt bridge Nov 19, 2021
@danielroe danielroe self-assigned this Dec 16, 2021
@danielroe danielroe transferred this issue from nuxt/framework Apr 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bridge enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants