vchikalkin 8aaae245a7 Refactor Apollo Client setup by removing createLink function
- Updated the `createApolloClient` function to directly handle authorization headers and GraphQL URI configuration, improving modularity and reducing complexity.
- Removed the `createLink` function, streamlining the client setup process and enhancing maintainability.
- Renamed type `Parameters` to `Parameters_` for clarity in the client function signature.
2025-10-07 10:14:09 +03:00

23 lines
641 B
TypeScript

import { env as environment } from '../config/env';
import { getToken } from '../config/token';
import { ApolloClient, InMemoryCache } from '@apollo/client/core';
type Parameters_ = { token: null | string | undefined };
export function createApolloClient(parameters?: Parameters_) {
return new ApolloClient({
cache: new InMemoryCache(),
headers: parameters?.token
? {
Authorization: `Bearer ${parameters.token}`,
}
: undefined,
uri: environment.URL_GRAPHQL_CACHED,
});
}
export async function getClientWithToken() {
const token = await getToken();
return createApolloClient({ token });
}