Files
telecom-platform/apps/web-dashboard/src/lib/apollo-client.ts
T
nutcas3 919e9906e8 feat: Update Apollo Client configuration to use explicit constructors and fix context link implementation
- Replace createHttpLink with HttpLink constructor
- Replace setContext with SetContextLink constructor
- Update authLink to use prevContext parameter and spread operator for proper context merging
- Replace from with ApolloLink.from for link composition
- Remove ApolloProvider wrapper from Providers component (render children directly)
2026-04-25 03:40:28 +03:00

56 lines
1.3 KiB
TypeScript

import { ApolloClient, InMemoryCache, HttpLink, ApolloLink } from '@apollo/client';
import { SetContextLink } from '@apollo/client/link/context';
// GraphQL API endpoint
const httpLink = new HttpLink({
uri: process.env.NEXT_PUBLIC_API_SERVER_URL || 'http://localhost:8080/v1/graphql',
});
// Auth link to add authentication token to requests
const authLink = new SetContextLink((prevContext, operation) => {
// Get the authentication token from local storage if it exists
const token = localStorage.getItem('auth_token');
return {
...prevContext,
headers: {
...prevContext.headers,
authorization: token ? `Bearer ${token}` : '',
},
};
});
// Create Apollo Client instance
export const apolloClient = new ApolloClient({
link: ApolloLink.from([authLink, httpLink]),
cache: new InMemoryCache(),
defaultOptions: {
watchQuery: {
fetchPolicy: 'cache-and-network',
},
query: {
fetchPolicy: 'network-only',
},
mutate: {
fetchPolicy: 'network-only',
},
},
});
// GraphQL queries and mutations can be defined here
// Example:
/*
import { gql } from '@apollo/client';
export const GET_SERVICES = gql`
query GetServices {
services {
id
name
status
health
}
}
`;
*/