mirror of
https://github.com/andwati/telecom-platform.git
synced 2026-10-23 13:12:16 +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';
|
||||
|
||||
import { ApolloProvider } from '@apollo/client';
|
||||
import { apolloClient } from '@/lib/apollo-client';
|
||||
|
||||
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 { setContext } from '@apollo/client/link/context';
|
||||
import { ApolloClient, InMemoryCache, HttpLink, ApolloLink } from '@apollo/client';
|
||||
import { SetContextLink } from '@apollo/client/link/context';
|
||||
|
||||
// GraphQL API endpoint
|
||||
const httpLink = createHttpLink({
|
||||
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 = setContext((_, { headers }) => {
|
||||
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: {
|
||||
...headers,
|
||||
...prevContext.headers,
|
||||
authorization: token ? `Bearer ${token}` : '',
|
||||
},
|
||||
};
|
||||
@@ -21,7 +22,7 @@ const authLink = setContext((_, { headers }) => {
|
||||
|
||||
// Create Apollo Client instance
|
||||
export const apolloClient = new ApolloClient({
|
||||
link: from([authLink, httpLink]),
|
||||
link: ApolloLink.from([authLink, httpLink]),
|
||||
cache: new InMemoryCache(),
|
||||
defaultOptions: {
|
||||
watchQuery: {
|
||||
|
||||
Reference in New Issue
Block a user