schon/storefront/plugins/apollo.ts
Egor fureunoir Gorbunov cc11da01f9 refactor(storefront): replace evibes logo with schon logo in SVG format
Updated the SVG logo file in storefront to replace evibes branding with schon. Includes enhanced styling and additional view properties for resolution compatibility.
2026-02-05 17:23:59 +03:00

50 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 { $apollo } = nuxtApp as any;
const errorLink = onError((err) => {
nuxtApp.callHook('apollo:error', err);
});
const authLink = setContext(async (_, { headers }) => {
const localeCookie = useCookie(useAppConfig().COOKIES_LOCALE_KEY);
const token = useCookie(useAppConfig().COOKIES_ACCESS_TOKEN_KEY);
const hdrs: Record<string,string> = {
...headers,
'Accept-Language': localeCookie.value || 'en-gb'
};
if (token.value) {
hdrs['X-SCHON-AUTH'] = `Bearer ${token.value}`;
}
return { headers: hdrs };
});
const customLink = new ApolloLink((operation, forward) => {
return forward(operation).map((data) => {
return data;
});
});
const httpLink = createUploadLink({
uri: `https://api.${runtime.public.schonBaseDomain}/graphql/`
});
$apollo.defaultClient.setLink(from([
errorLink,
authLink,
customLink,
httpLink,
]));
provideApolloClient($apollo.defaultClient);
});