Open munjalpatel opened 1 year ago
For advanced cases, I normally use @vue/apollo-composable
directly with something similar to this custom plugin setup:
apolloPlugin.ts:
import {
DefaultApolloClient,
provideApolloClient,
} from '@vue/apollo-composable';
import {
ApolloClient,
createHttpLink,
InMemoryCache,
} from '@apollo/client/core';
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.hook('vue:setup', () => {
const {
$config: { baseUrl },
} = useNuxtApp();
const httpLink = createHttpLink({
uri: `${baseUrl}/graphql`,
});
const cache = new InMemoryCache({
typePolicies: {
Users: {
fields: {
details: {
merge(_, incoming) {
return incoming;
},
},
},
},
},
});
const apolloClient = new ApolloClient({
link: httpLink,
cache,
});
provideApolloClient(apolloClient);
nuxtApp.provide('apollo', { DefaultApolloClient, apolloClient });
});
});
And always remember to have a proper id
field on all objects and subfields you want to work with, the apollo cache will not work otherwise.
Your use case
I want to define caching behavior by specifying custom
merge
function inInMemoryCache
because I am getting the following errors in console.But I couldn't find a way to do this in Nuxt Apollo.
The solution you'd like
Allow customizing
InMemoryCache
Possible alternatives
No response
Additional information
No response