Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

Jamiewarb
Copy link

@Jamiewarb Jamiewarb commented Dec 20, 2021

Providing an Apollo Client

Nuxt Bridge exposes the Nuxt 2 context via nuxtApp.nuxt2Context.
However, when assining the apolloProvider to app.apolloProvider, the apolloProvider is not added to this context. (https://github.com/nuxt-community/apollo-module/blob/master/lib/templates/plugin.js#L115)

In order to get the apolloProvider onto this nuxt2Context, we must use inject().
However, it requires a different name than "apolloProvider" when injecting, or we get errors.

With these changes, it's now possible to provide the apollo client as before:

// layouts/default.vue
<script setup>
import { provideApolloClient } from '@vue/apollo-composable';

provideApolloClient(useNuxtApp().nuxt2Context.$theApolloProvider?.defaultClient);
</script>

Once the replacement for onGlobalSetup() is added, we can move this code back to a plugin: nuxt/framework#2408

Note: This is a short term solution for Nuxt Bridge, and will need revisiting Nuxt 3.

Nuxt Bridge exposes the Nuxt 2 context via nuxtApp.nuxt2Context.

However, when doing `app.apolloProvider`, the apolloProvider is not added to this context.

In order to get the apolloProvider onto this nuxt2Context, we must use inject().

However, it requires a different name than "apolloProvider" when injecting, or we get errors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Morty Proxy This is a proxified and sanitized view of the page, visit original site.