@@ -426,9 +426,7 @@ class AppSyncGraphQLResolver extends Router {
426
426
{
427
427
event : events ,
428
428
context,
429
- ...( this . sharedContext . size > 0 && {
430
- sharedContext : this . sharedContext ,
431
- } ) ,
429
+ ...this . #getSharedContextOnlyIfNotEmpty( ) ,
432
430
} ,
433
431
] ) ;
434
432
@@ -451,9 +449,7 @@ class AppSyncGraphQLResolver extends Router {
451
449
{
452
450
event,
453
451
context,
454
- ...( this . sharedContext . size > 0 && {
455
- sharedContext : this . sharedContext ,
456
- } ) ,
452
+ ...this . #getSharedContextOnlyIfNotEmpty( ) ,
457
453
} ,
458
454
] ) ;
459
455
results . push ( result ) ;
@@ -468,9 +464,7 @@ class AppSyncGraphQLResolver extends Router {
468
464
{
469
465
event : events [ i ] ,
470
466
context,
471
- ...( this . sharedContext . size > 0 && {
472
- sharedContext : this . sharedContext ,
473
- } ) ,
467
+ ...this . #getSharedContextOnlyIfNotEmpty( ) ,
474
468
} ,
475
469
] ) ;
476
470
results . push ( result ) ;
@@ -518,9 +512,7 @@ class AppSyncGraphQLResolver extends Router {
518
512
{
519
513
event,
520
514
context,
521
- ...( this . sharedContext . size > 0 && {
522
- sharedContext : this . sharedContext ,
523
- } ) ,
515
+ ...this . #getSharedContextOnlyIfNotEmpty( ) ,
524
516
} ,
525
517
]
526
518
) ;
@@ -546,6 +538,19 @@ class AppSyncGraphQLResolver extends Router {
546
538
error : 'An unknown error occurred' ,
547
539
} ;
548
540
}
541
+
542
+ /**
543
+ * Returns an object containing the shared context only if it has entries.
544
+ * This helps avoid passing an empty map to handlers.
545
+ */
546
+ #getSharedContextOnlyIfNotEmpty( ) : {
547
+ sharedContext : Map < string , unknown > | undefined ;
548
+ } {
549
+ return {
550
+ sharedContext :
551
+ this . sharedContext . size > 0 ? this . sharedContext : undefined ,
552
+ } ;
553
+ }
549
554
}
550
555
551
556
export { AppSyncGraphQLResolver } ;
0 commit comments