@@ -1781,18 +1781,48 @@ export function createSourceEventStream(
1781
1781
function createSourceEventStreamImpl (
1782
1782
exeContext : ExecutionContext ,
1783
1783
) : PromiseOrValue < AsyncIterable < unknown > | ExecutionResult > {
1784
- try {
1785
- const eventStream = executeSubscription ( exeContext ) ;
1786
- if ( isPromise ( eventStream ) ) {
1787
- return eventStream . then ( undefined , ( error ) => ( { errors : [ error ] } ) ) ;
1784
+ try {
1785
+
1786
+ const eventStream = executeSubscription ( exeContext ) ;
1787
+
1788
+ if ( isPromise ( eventStream ) ) {
1789
+ // Handle promise errors
1790
+ return eventStream . then (
1791
+ data => ( { data } ) ,
1792
+ error => ( { errors : [ error ] } )
1793
+ ) ;
1794
+ }
1795
+
1796
+ const wrappedStream = {
1797
+ async * [ Symbol . asyncIterator ] ( ) {
1798
+ try {
1799
+ yield * eventStream ;
1800
+ } catch ( error ) {
1801
+ yield { errors : [ error ] } ;
1802
+ }
1788
1803
}
1804
+ } ;
1789
1805
1790
- return eventStream ;
1791
- } catch ( error ) {
1792
- return { errors : [ error ] } ;
1806
+ return wrappedStream ;
1807
+
1808
+ } catch ( error ) {
1809
+ // Handle sync errors
1810
+ return { errors : [ error ] } ;
1811
+ }
1812
+
1813
+ function resolve ( payload ) {
1814
+ if ( payload . errors ) {
1815
+ throw payload . errors [ 0 ] ;
1816
+ } else {
1817
+ return payload . data ;
1793
1818
}
1794
1819
}
1795
1820
1821
+ const stream = executeSubscription ( ) ;
1822
+ mapAsyncIterable ( stream , resolve ) ;
1823
+
1824
+ }
1825
+
1796
1826
function executeSubscription (
1797
1827
exeContext : ExecutionContext ,
1798
1828
) : PromiseOrValue < AsyncIterable < unknown > > {
0 commit comments