1 Reply
import {
ApolloClient,
InMemoryCache,
createHttpLink,
} from '@apollo/client/core'
import {
DefaultApolloClient,
provideApolloClient,
} from '@vue/apollo-composable'
import { defineNuxtPlugin } from '#app'
export default defineNuxtPlugin((nuxtApp) => {
const httpLink = createHttpLink({
credentials: 'omit',
uri: 'http://127.0.0.1:4000/graphql',
})
const cache = new InMemoryCache()
let apolloClient: ApolloClient<any>
if (process.server) {
apolloClient = new ApolloClient({
ssrMode: true,
link: httpLink,
cache,
})
nuxtApp.hook('app:rendered', () => {
nuxtApp.payload.data.apollo = apolloClient.extract()
})
}
else {
apolloClient = new ApolloClient({
link: httpLink,
cache,
ssrForceFetchDelay: 100,
})
}
provideApolloClient(apolloClient)
nuxtApp.provide('apollo', { DefaultApolloClient, apolloClient })
})
import {
ApolloClient,
InMemoryCache,
createHttpLink,
} from '@apollo/client/core'
import {
DefaultApolloClient,
provideApolloClient,
} from '@vue/apollo-composable'
import { defineNuxtPlugin } from '#app'
export default defineNuxtPlugin((nuxtApp) => {
const httpLink = createHttpLink({
credentials: 'omit',
uri: 'http://127.0.0.1:4000/graphql',
})
const cache = new InMemoryCache()
let apolloClient: ApolloClient<any>
if (process.server) {
apolloClient = new ApolloClient({
ssrMode: true,
link: httpLink,
cache,
})
nuxtApp.hook('app:rendered', () => {
nuxtApp.payload.data.apollo = apolloClient.extract()
})
}
else {
apolloClient = new ApolloClient({
link: httpLink,
cache,
ssrForceFetchDelay: 100,
})
}
provideApolloClient(apolloClient)
nuxtApp.provide('apollo', { DefaultApolloClient, apolloClient })
})