@@ -422,9 +422,7 @@ class AppSyncGraphQLResolver extends Router {
422
422
{
423
423
event : events ,
424
424
context,
425
- ...( this . sharedContext . size > 0 && {
426
- sharedContext : this . sharedContext ,
427
- } ) ,
425
+ ...this . #getSharedContextOnlyIfNotEmpty( ) ,
428
426
} ,
429
427
] ) ;
430
428
@@ -447,9 +445,7 @@ class AppSyncGraphQLResolver extends Router {
447
445
{
448
446
event,
449
447
context,
450
- ...( this . sharedContext . size > 0 && {
451
- sharedContext : this . sharedContext ,
452
- } ) ,
448
+ ...this . #getSharedContextOnlyIfNotEmpty( ) ,
453
449
} ,
454
450
] ) ;
455
451
results . push ( result ) ;
@@ -464,9 +460,7 @@ class AppSyncGraphQLResolver extends Router {
464
460
{
465
461
event : events [ i ] ,
466
462
context,
467
- ...( this . sharedContext . size > 0 && {
468
- sharedContext : this . sharedContext ,
469
- } ) ,
463
+ ...this . #getSharedContextOnlyIfNotEmpty( ) ,
470
464
} ,
471
465
] ) ;
472
466
results . push ( result ) ;
@@ -514,9 +508,7 @@ class AppSyncGraphQLResolver extends Router {
514
508
{
515
509
event,
516
510
context,
517
- ...( this . sharedContext . size > 0 && {
518
- sharedContext : this . sharedContext ,
519
- } ) ,
511
+ ...this . #getSharedContextOnlyIfNotEmpty( ) ,
520
512
} ,
521
513
]
522
514
) ;
@@ -542,6 +534,19 @@ class AppSyncGraphQLResolver extends Router {
542
534
error : 'An unknown error occurred' ,
543
535
} ;
544
536
}
537
+
538
+ /**
539
+ * Returns an object containing the shared context only if it has entries.
540
+ * This helps avoid passing an empty map to handlers.
541
+ */
542
+ #getSharedContextOnlyIfNotEmpty( ) : {
543
+ sharedContext : Map < string , unknown > | undefined ;
544
+ } {
545
+ return {
546
+ sharedContext :
547
+ this . sharedContext . size > 0 ? this . sharedContext : undefined ,
548
+ } ;
549
+ }
545
550
}
546
551
547
552
export { AppSyncGraphQLResolver } ;
0 commit comments