schon/storefront/plugins/apollo.ts
Alexandr SaVBaD Waltz 64730a1d4e Features: 1) Add appStore integration for managing search overlay state in search.vue; 2) Enhance expiration date formatting in promocodes.vue with detailed and localized time display; 3) Replace avatar image handling in settings.vue with nuxt-img for better performance and format support;
Fixes: 1) Add missing type annotations for `isSearchActive` in `useSearchUi.ts`; 2) Resolve improper conditional rendering in empty state templates across multiple files; 3) Remove unnecessary `console.log` calls in `goTo` function;

Extra: 1) Update SCSS styles including border thickness, colors, and padding tweaks; 2) Refactor `loader.vue` to use `<span>` instead of `<li>` for dots and adjust size; 3) Clean up obsolete TODOs, comments, and unused imports.
2025-07-15 21:25:51 +10:00

49 lines
No EOL
1.4 KiB
TypeScript

import { from, ApolloLink } from '@apollo/client/core';
import { onError } from '@apollo/client/link/error';
import { setContext } from '@apollo/client/link/context';
import { provideApolloClient } from '@vue/apollo-composable';
import createUploadLink from "apollo-upload-client/createUploadLink.mjs";
import { useAppConfig } from '~/composables/config';
export default defineNuxtPlugin((nuxtApp) => {
const runtime = useRuntimeConfig();
const localeCookie = useCookie(useAppConfig().COOKIES_LOCALE_KEY);
const token = useCookie(useAppConfig().COOKIES_ACCESS_TOKEN_KEY).value || '';
const { $apollo } = nuxtApp as any;
const errorLink = onError((err) => {
nuxtApp.callHook('apollo:error', err);
});
const authLink = setContext(async (_, { headers }) => {
const hdrs: Record<string,string> = {
...headers,
'Accept-Language': localeCookie.value || 'en-gb'
};
if (token) {
hdrs['X-EVIBES-AUTH'] = `Bearer ${token}`;
}
return { headers: hdrs };
});
const customLink = new ApolloLink((operation, forward) => {
return forward(operation).map((data) => {
return data;
});
});
const httpLink = createUploadLink({
uri: `https://api.${runtime.public.evibesBaseDomain}/graphql/`
});
$apollo.defaultClient.setLink(from([
errorLink,
authLink,
customLink,
httpLink,
]));
provideApolloClient($apollo.defaultClient);
});