@@ -422,9 +422,7 @@ class AppSyncGraphQLResolver extends Router {
422422 {
423423 event : events ,
424424 context,
425- ...( this . sharedContext . size > 0 && {
426- sharedContext : this . sharedContext ,
427- } ) ,
425+ ...this . #getSharedContextOnlyIfNotEmpty( ) ,
428426 } ,
429427 ] ) ;
430428
@@ -447,9 +445,7 @@ class AppSyncGraphQLResolver extends Router {
447445 {
448446 event,
449447 context,
450- ...( this . sharedContext . size > 0 && {
451- sharedContext : this . sharedContext ,
452- } ) ,
448+ ...this . #getSharedContextOnlyIfNotEmpty( ) ,
453449 } ,
454450 ] ) ;
455451 results . push ( result ) ;
@@ -464,9 +460,7 @@ class AppSyncGraphQLResolver extends Router {
464460 {
465461 event : events [ i ] ,
466462 context,
467- ...( this . sharedContext . size > 0 && {
468- sharedContext : this . sharedContext ,
469- } ) ,
463+ ...this . #getSharedContextOnlyIfNotEmpty( ) ,
470464 } ,
471465 ] ) ;
472466 results . push ( result ) ;
@@ -514,9 +508,7 @@ class AppSyncGraphQLResolver extends Router {
514508 {
515509 event,
516510 context,
517- ...( this . sharedContext . size > 0 && {
518- sharedContext : this . sharedContext ,
519- } ) ,
511+ ...this . #getSharedContextOnlyIfNotEmpty( ) ,
520512 } ,
521513 ]
522514 ) ;
@@ -542,6 +534,19 @@ class AppSyncGraphQLResolver extends Router {
542534 error : 'An unknown error occurred' ,
543535 } ;
544536 }
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+ }
545550}
546551
547552export { AppSyncGraphQLResolver } ;
0 commit comments