@@ -5,6 +5,7 @@ import { ApolloClient, ApolloLink, HttpLink, InMemoryCache } from '@apollo/clien
55import { CombinedGraphQLErrors , CombinedProtocolErrors } from '@apollo/client/errors'
66import { SetContextLink } from '@apollo/client/link/context'
77import { ErrorLink } from '@apollo/client/link/error'
8+ import { RetryLink } from '@apollo/client/link/retry'
89import { GraphQLWsLink } from '@apollo/client/link/subscriptions'
910import { getMainDefinition } from '@apollo/client/utilities'
1011import { defu } from 'defu'
@@ -47,7 +48,7 @@ export async function createApolloClient({ clientId, config, nuxtApp }: CreateAp
4748 }
4849 }
4950
50- // Create an auth link to inject authentication token into headers
51+ // Create an auth combinedLink to inject authentication token into headers
5152 const authLink = new SetContextLink ( ( prevContext ) => {
5253 return defu (
5354 {
@@ -59,13 +60,13 @@ export async function createApolloClient({ clientId, config, nuxtApp }: CreateAp
5960 )
6061 } )
6162
62- // Create an HTTP link
63+ // Create an HTTP combinedLink
6364 const httpLink = new HttpLink ( {
6465 ...config . httpLinkOptions ,
6566 uri : config . httpEndpoint
6667 } )
6768
68- // Create an error link to handle and broadcast errors
69+ // Create an error combinedLink to handle and broadcast errors
6970 const errorLink = new ErrorLink ( ( { error, forward, operation } ) => {
7071 // Prepare typed payload for hook
7172 const payload : ApolloErrorHookPayload = {
@@ -103,8 +104,8 @@ export async function createApolloClient({ clientId, config, nuxtApp }: CreateAp
103104 }
104105 }
105106
106- // Create a WebSocket link for subscriptions (client-side only)
107- let link = httpLink
107+ // Create a WebSocket combinedLink for subscriptions (client-side only)
108+ let combinedLink = httpLink
108109 if ( import . meta. client && config . wsEndpoint ) {
109110 try {
110111 // Dynamic import to avoid bundling graphql-ws on the server
@@ -126,7 +127,7 @@ export async function createApolloClient({ clientId, config, nuxtApp }: CreateAp
126127 // Use split to route operations:
127128 // - Subscriptions go through WebSocket
128129 // - Queries and mutations go through HTTP
129- link = ApolloLink . split (
130+ combinedLink = ApolloLink . split (
130131 ( { query } ) => {
131132 const definition = getMainDefinition ( query )
132133 return (
@@ -147,6 +148,8 @@ export async function createApolloClient({ clientId, config, nuxtApp }: CreateAp
147148 }
148149 }
149150
151+ const retryLink = new RetryLink ( )
152+
150153 const defaultOptions : ApolloClient . DefaultOptions = defu ( {
151154 query : {
152155 fetchPolicy : import . meta. server ? 'network-only' : 'cache-first'
@@ -164,9 +167,9 @@ export async function createApolloClient({ clientId, config, nuxtApp }: CreateAp
164167 enabled : config . devtools ?? config . devtools ,
165168 name : clientId
166169 } ,
167- // Combine the auth link , error link , and main link chain
170+ // Combine the auth combinedLink , error combinedLink , and main combinedLink chain
168171 // Order matters: auth -> error -> http/ws
169- link : ApolloLink . from ( [ authLink , errorLink , link ] ) ,
172+ link : ApolloLink . from ( [ authLink , errorLink , retryLink , combinedLink ] ) ,
170173 // Prevent refetching immediately after SSR hydration
171174 ssrForceFetchDelay : 100 ,
172175 // Enable server-side rendering support
0 commit comments