@@ -69,7 +69,7 @@ export interface UnifiedGraphHandlerOpts {
69
69
onDelegationPlanHooks ?: OnDelegationPlanHook < any > [ ] ;
70
70
onDelegationStageExecuteHooks ?: OnDelegationStageExecuteHook < any > [ ] ;
71
71
onDelegateHooks ?: OnDelegateHook < unknown > [ ] ;
72
- log : Logger ;
72
+ log ? : Logger ;
73
73
}
74
74
75
75
export interface UnifiedGraphHandlerResult {
@@ -81,7 +81,7 @@ export interface UnifiedGraphHandlerResult {
81
81
82
82
export interface UnifiedGraphManagerOptions < TContext > {
83
83
getUnifiedGraph (
84
- ctx : TransportContext ,
84
+ ctx : TransportContext | undefined ,
85
85
) : MaybePromise < GraphQLSchema | string | DocumentNode > ;
86
86
// Handle the unified graph by any specification
87
87
handleUnifiedGraph ?: UnifiedGraphHandler ;
@@ -93,7 +93,7 @@ export interface UnifiedGraphManagerOptions<TContext> {
93
93
additionalResolvers ?:
94
94
| IResolvers < unknown , TContext >
95
95
| IResolvers < unknown , TContext > [ ] ;
96
- transportContext : TransportContext ;
96
+ transportContext ? : TransportContext ;
97
97
onSubgraphExecuteHooks ?: OnSubgraphExecuteHook < TContext > [ ] ;
98
98
// TODO: Will be removed later once we get rid of v0
99
99
onDelegateHooks ?: OnDelegateHook < unknown > [ ] ;
@@ -156,7 +156,7 @@ export class UnifiedGraphManager<TContext> implements AsyncDisposable {
156
156
this . onDelegationStageExecuteHooks =
157
157
opts ?. onDelegationStageExecuteHooks || [ ] ;
158
158
if ( opts . pollingInterval != null ) {
159
- opts . transportContext . log . debug (
159
+ opts . transportContext ? .log . debug (
160
160
`Starting polling to Supergraph with interval ${ millisecondsToStr ( opts . pollingInterval ) } ` ,
161
161
) ;
162
162
}
@@ -169,14 +169,14 @@ export class UnifiedGraphManager<TContext> implements AsyncDisposable {
169
169
this . lastLoadTime != null &&
170
170
Date . now ( ) - this . lastLoadTime >= this . opts . pollingInterval
171
171
) {
172
- this . opts ?. transportContext . log . debug ( `Polling Supergraph` ) ;
172
+ this . opts ?. transportContext ? .log . debug ( `Polling Supergraph` ) ;
173
173
this . polling$ = handleMaybePromise (
174
174
( ) => this . getAndSetUnifiedGraph ( ) ,
175
175
( ) => {
176
176
this . polling$ = undefined ;
177
177
} ,
178
178
( err ) => {
179
- this . opts . transportContext . log . error (
179
+ this . opts . transportContext ? .log . error (
180
180
err ,
181
181
'Failed to poll Supergraph' ,
182
182
) ;
@@ -186,19 +186,20 @@ export class UnifiedGraphManager<TContext> implements AsyncDisposable {
186
186
}
187
187
if ( ! this . unifiedGraph ) {
188
188
if ( ! this . initialUnifiedGraph$ ) {
189
- this . opts ?. transportContext . log . debug (
189
+ this . opts ?. transportContext ? .log . debug (
190
190
'Fetching the initial Supergraph' ,
191
191
) ;
192
- if ( this . opts . transportContext . cache ) {
193
- this . opts . transportContext . log . debug (
192
+ if ( this . opts . transportContext ? .cache ) {
193
+ this . opts . transportContext ? .log . debug (
194
194
{ key : UNIFIEDGRAPH_CACHE_KEY } ,
195
195
'Searching for Supergraph in cache...' ,
196
196
) ;
197
197
this . initialUnifiedGraph$ = handleMaybePromise (
198
- ( ) => this . opts . transportContext . cache ?. get ( UNIFIEDGRAPH_CACHE_KEY ) ,
198
+ ( ) =>
199
+ this . opts . transportContext ?. cache ?. get ( UNIFIEDGRAPH_CACHE_KEY ) ,
199
200
( cachedUnifiedGraph ) => {
200
201
if ( cachedUnifiedGraph ) {
201
- this . opts . transportContext . log . debug (
202
+ this . opts . transportContext ? .log . debug (
202
203
{ key : UNIFIEDGRAPH_CACHE_KEY } ,
203
204
'Found Supergraph in cache' ,
204
205
) ;
@@ -217,7 +218,7 @@ export class UnifiedGraphManager<TContext> implements AsyncDisposable {
217
218
( ) => this . initialUnifiedGraph$ ! ,
218
219
( v ) => {
219
220
this . initialUnifiedGraph$ = undefined ;
220
- this . opts . transportContext . log . debug (
221
+ this . opts . transportContext ? .log . debug (
221
222
{ key : UNIFIEDGRAPH_CACHE_KEY } ,
222
223
'Initial Supergraph fetched' ,
223
224
) ;
@@ -241,7 +242,7 @@ export class UnifiedGraphManager<TContext> implements AsyncDisposable {
241
242
this . lastLoadedUnifiedGraph != null &&
242
243
compareSchemas ( loadedUnifiedGraph , this . lastLoadedUnifiedGraph )
243
244
) {
244
- this . opts . transportContext . log . debug (
245
+ this . opts . transportContext ? .log . debug (
245
246
'Supergraph has not been changed, skipping...' ,
246
247
) ;
247
248
this . lastLoadTime = Date . now ( ) ;
@@ -268,18 +269,18 @@ export class UnifiedGraphManager<TContext> implements AsyncDisposable {
268
269
// 60 seconds making sure the unifiedgraph is not kept forever
269
270
// NOTE: we default to 60s because Cloudflare KV TTL does not accept anything less
270
271
60 ;
271
- this . opts . transportContext . log . debug (
272
+ this . opts . transportContext ? .log . debug (
272
273
{ ttl, key : UNIFIEDGRAPH_CACHE_KEY } ,
273
274
'Caching Supergraph' ,
274
275
) ;
275
276
const logCacheSetError = ( err : unknown ) => {
276
- this . opts . transportContext . log . debug (
277
+ this . opts . transportContext ? .log . debug (
277
278
{ err, ttl, key : UNIFIEDGRAPH_CACHE_KEY } ,
278
279
'Unable to cache Supergraph' ,
279
280
) ;
280
281
} ;
281
282
try {
282
- const cacheSet$ = this . opts . transportContext . cache . set (
283
+ const cacheSet$ = this . opts . transportContext ? .cache . set (
283
284
UNIFIEDGRAPH_CACHE_KEY ,
284
285
serializedUnifiedGraph ,
285
286
{ ttl } ,
@@ -292,7 +293,7 @@ export class UnifiedGraphManager<TContext> implements AsyncDisposable {
292
293
logCacheSetError ( e ) ;
293
294
}
294
295
} catch ( err : any ) {
295
- this . opts . transportContext . log . error (
296
+ this . opts . transportContext ? .log . error (
296
297
err ,
297
298
'Failed to initiate caching of Supergraph' ,
298
299
) ;
@@ -320,7 +321,7 @@ export class UnifiedGraphManager<TContext> implements AsyncDisposable {
320
321
onDelegationPlanHooks : this . onDelegationPlanHooks ,
321
322
onDelegationStageExecuteHooks : this . onDelegationStageExecuteHooks ,
322
323
onDelegateHooks : this . opts . onDelegateHooks ,
323
- log : this . opts . transportContext . log ,
324
+ log : this . opts . transportContext ? .log ,
324
325
} ) ;
325
326
const transportExecutorStack = new AsyncDisposableStack ( ) ;
326
327
const onSubgraphExecute = getOnSubgraphExecute ( {
@@ -362,7 +363,7 @@ export class UnifiedGraphManager<TContext> implements AsyncDisposable {
362
363
} ,
363
364
} ,
364
365
) ;
365
- this . opts . transportContext . log . debug (
366
+ this . opts . transportContext ? .log . debug (
366
367
'Supergraph has been changed, updating...' ,
367
368
) ;
368
369
}
@@ -374,7 +375,7 @@ export class UnifiedGraphManager<TContext> implements AsyncDisposable {
374
375
} ,
375
376
( err ) => {
376
377
this . disposeReason = undefined ;
377
- this . opts . transportContext . log . error (
378
+ this . opts . transportContext ? .log . error (
378
379
err ,
379
380
'Failed to dispose the existing transports and executors' ,
380
381
) ;
@@ -394,11 +395,11 @@ export class UnifiedGraphManager<TContext> implements AsyncDisposable {
394
395
395
396
private getAndSetUnifiedGraph ( ) : MaybePromise < GraphQLSchema > {
396
397
return handleMaybePromise (
397
- ( ) => this . opts . getUnifiedGraph ( this . opts . transportContext || { } ) ,
398
+ ( ) => this . opts . getUnifiedGraph ( this . opts . transportContext ) ,
398
399
( loadedUnifiedGraph : string | GraphQLSchema | DocumentNode ) =>
399
400
this . handleLoadedUnifiedGraph ( loadedUnifiedGraph ) ,
400
401
( err ) => {
401
- this . opts . transportContext . log . error ( err , 'Failed to load Supergraph' ) ;
402
+ this . opts . transportContext ? .log . error ( err , 'Failed to load Supergraph' ) ;
402
403
this . lastLoadTime = Date . now ( ) ;
403
404
this . disposeReason = undefined ;
404
405
this . polling$ = undefined ;
0 commit comments