6
6
MaybeAsyncIterable ,
7
7
} from '@graphql-tools/utils' ;
8
8
import { handleMaybePromise , MaybePromise } from '@whatwg-node/promise-helpers' ;
9
- import { GraphQLResolveInfo } from 'graphql' ;
10
9
import { GatewayPlugin } from '../types' ;
11
10
12
11
export const RETRY_SYMBOL = Symbol . for ( '@hive-gateway/runtime/upstreamRetry' ) ;
@@ -69,14 +68,11 @@ export function useUpstreamRetry<TContext extends Record<string, any>>(
69
68
return {
70
69
onSubgraphExecute ( {
71
70
subgraphName,
72
- executionRequest : subgraphExecutionRequest ,
71
+ executionRequest,
73
72
executor,
74
73
setExecutor,
75
74
} ) {
76
- const optsForReq = retryOptions ( {
77
- subgraphName,
78
- executionRequest : subgraphExecutionRequest ,
79
- } ) ;
75
+ const optsForReq = retryOptions ( { subgraphName, executionRequest } ) ;
80
76
if ( optsForReq ) {
81
77
const {
82
78
maxRetries,
@@ -106,7 +102,7 @@ export function useUpstreamRetry<TContext extends Record<string, any>>(
106
102
} ,
107
103
} = optsForReq ;
108
104
if ( maxRetries > 0 ) {
109
- setExecutor ( function ( executorExecutionRequest : ExecutionRequest ) {
105
+ setExecutor ( function ( executionRequest : ExecutionRequest ) {
110
106
let attemptsLeft = maxRetries + 1 ;
111
107
let executionResult : MaybeAsyncIterable < ExecutionResult > ;
112
108
let currRetryDelay = retryDelay ;
@@ -120,30 +116,21 @@ export function useUpstreamRetry<TContext extends Record<string, any>>(
120
116
const requestTime = Date . now ( ) ;
121
117
attemptsLeft -- ;
122
118
123
- const attemptExecutionRequest : RetryExecutionRequest = {
124
- ...executorExecutionRequest ,
125
- [ RETRY_SYMBOL ] : {
126
- attempt : maxRetries - attemptsLeft ,
127
- executionRequest : executorExecutionRequest ,
128
- } ,
119
+ // @ts -expect-error we rather mutatate the executionRequest because we strict compare it
120
+ executionRequest [ RETRY_SYMBOL ] = {
121
+ attempt : maxRetries - attemptsLeft ,
122
+ executionRequest,
129
123
} ;
130
- attemptExecutionRequest . info = {
131
- ...executorExecutionRequest . info ,
132
- executionRequest : attemptExecutionRequest ,
133
- } as GraphQLResolveInfo ;
134
124
135
125
return handleMaybePromise (
136
- ( ) => {
137
- return executor ( attemptExecutionRequest ) ;
138
- } ,
126
+ ( ) => executor ( executionRequest ) ,
139
127
( currRes ) => {
140
128
executionResult = currRes ;
141
129
let retryAfterSecondsFromHeader : number | undefined ;
142
- const response = executionRequestResponseMap . get (
143
- attemptExecutionRequest ,
144
- ) ;
130
+ const response =
131
+ executionRequestResponseMap . get ( executionRequest ) ;
145
132
// Remove the response from the map after used so we don't see it again
146
- executionRequestResponseMap . delete ( attemptExecutionRequest ) ;
133
+ executionRequestResponseMap . delete ( executionRequest ) ;
147
134
const retryAfterHeader =
148
135
response ?. headers . get ( 'Retry-After' ) ;
149
136
if ( retryAfterHeader ) {
@@ -161,7 +148,7 @@ export function useUpstreamRetry<TContext extends Record<string, any>>(
161
148
currRetryDelay * retryDelayFactor ;
162
149
if (
163
150
shouldRetry ( {
164
- executionRequest : attemptExecutionRequest ,
151
+ executionRequest,
165
152
executionResult,
166
153
response,
167
154
} )
0 commit comments