From 919e9906e85d43610dc3b55728477a1dac853b5e Mon Sep 17 00:00:00 2001 From: nutcas3 Date: Sat, 25 Apr 2026 03:40:28 +0300 Subject: [PATCH] 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) --- apps/web-dashboard/src/app/providers.tsx | 5 +---- apps/web-dashboard/src/lib/apollo-client.ts | 13 +++++++------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/apps/web-dashboard/src/app/providers.tsx b/apps/web-dashboard/src/app/providers.tsx index 43b8b3e..ae7998e 100644 --- a/apps/web-dashboard/src/app/providers.tsx +++ b/apps/web-dashboard/src/app/providers.tsx @@ -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 {children}; + return <>{children}; } diff --git a/apps/web-dashboard/src/lib/apollo-client.ts b/apps/web-dashboard/src/lib/apollo-client.ts index 513fa3a..790e97c 100644 --- a/apps/web-dashboard/src/lib/apollo-client.ts +++ b/apps/web-dashboard/src/lib/apollo-client.ts @@ -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: {