mirror of
https://github.com/andwati/telecom-platform.git
synced 2026-11-28 06:48:47 +00:00
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)
This commit is contained in:
@@ -1,8 +1,5 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { ApolloProvider } from '@apollo/client';
|
|
||||||
import { apolloClient } from '@/lib/apollo-client';
|
|
||||||
|
|
||||||
export function Providers({ children }: { children: React.ReactNode }) {
|
export function Providers({ children }: { children: React.ReactNode }) {
|
||||||
return <ApolloProvider client={apolloClient}>{children}</ApolloProvider>;
|
return <>{children}</>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,20 @@
|
|||||||
import { ApolloClient, InMemoryCache, createHttpLink, from } from '@apollo/client';
|
import { ApolloClient, InMemoryCache, HttpLink, ApolloLink } from '@apollo/client';
|
||||||
import { setContext } from '@apollo/client/link/context';
|
import { SetContextLink } from '@apollo/client/link/context';
|
||||||
|
|
||||||
// GraphQL API endpoint
|
// GraphQL API endpoint
|
||||||
const httpLink = createHttpLink({
|
const httpLink = new HttpLink({
|
||||||
uri: process.env.NEXT_PUBLIC_API_SERVER_URL || 'http://localhost:8080/v1/graphql',
|
uri: process.env.NEXT_PUBLIC_API_SERVER_URL || 'http://localhost:8080/v1/graphql',
|
||||||
});
|
});
|
||||||
|
|
||||||
// Auth link to add authentication token to requests
|
// Auth link to add authentication token to requests
|
||||||
const authLink = setContext((_, { headers }) => {
|
const authLink = new SetContextLink((prevContext, operation) => {
|
||||||
// Get the authentication token from local storage if it exists
|
// Get the authentication token from local storage if it exists
|
||||||
const token = localStorage.getItem('auth_token');
|
const token = localStorage.getItem('auth_token');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
...prevContext,
|
||||||
headers: {
|
headers: {
|
||||||
...headers,
|
...prevContext.headers,
|
||||||
authorization: token ? `Bearer ${token}` : '',
|
authorization: token ? `Bearer ${token}` : '',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -21,7 +22,7 @@ const authLink = setContext((_, { headers }) => {
|
|||||||
|
|
||||||
// Create Apollo Client instance
|
// Create Apollo Client instance
|
||||||
export const apolloClient = new ApolloClient({
|
export const apolloClient = new ApolloClient({
|
||||||
link: from([authLink, httpLink]),
|
link: ApolloLink.from([authLink, httpLink]),
|
||||||
cache: new InMemoryCache(),
|
cache: new InMemoryCache(),
|
||||||
defaultOptions: {
|
defaultOptions: {
|
||||||
watchQuery: {
|
watchQuery: {
|
||||||
|
|||||||
Reference in New Issue
Block a user