@@ -1798,6 +1798,72 @@ function executeDeferredFragment(
1798
1798
asyncPayloadRecord . addData ( promiseOrData ) ;
1799
1799
}
1800
1800
1801
+ async function completedItemsFromPromisedItem (
1802
+ exeContext : ExecutionContext ,
1803
+ itemType : GraphQLOutputType ,
1804
+ fieldNodes : ReadonlyArray < FieldNode > ,
1805
+ info : GraphQLResolveInfo ,
1806
+ path : Path ,
1807
+ itemPath : Path ,
1808
+ item : Promise < unknown > ,
1809
+ asyncPayloadRecord : AsyncPayloadRecord ,
1810
+ ) : Promise < [ unknown ] | null > {
1811
+ try {
1812
+ try {
1813
+ const resolved = await item ;
1814
+ let completed = completeValue (
1815
+ exeContext ,
1816
+ itemType ,
1817
+ fieldNodes ,
1818
+ info ,
1819
+ itemPath ,
1820
+ resolved ,
1821
+ asyncPayloadRecord ,
1822
+ ) ;
1823
+ if ( isPromise ( completed ) ) {
1824
+ completed = await completed ;
1825
+ }
1826
+ return [ completed ] ;
1827
+ } catch ( rawError ) {
1828
+ const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
1829
+ const error = locatedError ( rawError , fieldNodes , pathToArray ( itemPath ) ) ;
1830
+ const handledError = handleFieldError ( error , itemType , errors ) ;
1831
+ filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1832
+ return [ handledError ] ;
1833
+ }
1834
+ } catch ( error ) {
1835
+ asyncPayloadRecord . errors . push ( error ) ;
1836
+ filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
1837
+ return null ;
1838
+ }
1839
+ }
1840
+
1841
+ async function completedItemsFromPromisedCompletedItem (
1842
+ exeContext : ExecutionContext ,
1843
+ itemType : GraphQLOutputType ,
1844
+ fieldNodes : ReadonlyArray < FieldNode > ,
1845
+ path : Path ,
1846
+ itemPath : Path ,
1847
+ completedItem : Promise < unknown > ,
1848
+ asyncPayloadRecord : AsyncPayloadRecord ,
1849
+ ) : Promise < [ unknown ] | null > {
1850
+ try {
1851
+ try {
1852
+ return [ await completedItem ] ;
1853
+ } catch ( rawError ) {
1854
+ const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
1855
+ const error = locatedError ( rawError , fieldNodes , pathToArray ( itemPath ) ) ;
1856
+ const handledError = handleFieldError ( error , itemType , errors ) ;
1857
+ filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1858
+ return [ handledError ] ;
1859
+ }
1860
+ } catch ( error ) {
1861
+ asyncPayloadRecord . errors . push ( error ) ;
1862
+ filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
1863
+ return null ;
1864
+ }
1865
+ }
1866
+
1801
1867
function executeStreamField (
1802
1868
path : Path ,
1803
1869
itemPath : Path ,
@@ -1816,24 +1882,18 @@ function executeStreamField(
1816
1882
exeContext,
1817
1883
} ) ;
1818
1884
if ( isPromise ( item ) ) {
1819
- const completedItems = completePromisedValue (
1820
- exeContext ,
1821
- itemType ,
1822
- fieldNodes ,
1823
- info ,
1824
- itemPath ,
1825
- item ,
1826
- asyncPayloadRecord ,
1827
- ) . then (
1828
- ( value ) => [ value ] ,
1829
- ( error ) => {
1830
- asyncPayloadRecord . errors . push ( error ) ;
1831
- filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
1832
- return null ;
1833
- } ,
1885
+ asyncPayloadRecord . addItems (
1886
+ completedItemsFromPromisedItem (
1887
+ exeContext ,
1888
+ itemType ,
1889
+ fieldNodes ,
1890
+ info ,
1891
+ path ,
1892
+ itemPath ,
1893
+ item ,
1894
+ asyncPayloadRecord ,
1895
+ ) ,
1834
1896
) ;
1835
-
1836
- asyncPayloadRecord . addItems ( completedItems ) ;
1837
1897
return asyncPayloadRecord ;
1838
1898
}
1839
1899
@@ -1866,27 +1926,17 @@ function executeStreamField(
1866
1926
}
1867
1927
1868
1928
if ( isPromise ( completedItem ) ) {
1869
- const completedItems = completedItem
1870
- . then ( undefined , ( rawError ) => {
1871
- const error = locatedError ( rawError , fieldNodes , pathToArray ( itemPath ) ) ;
1872
- const handledError = handleFieldError (
1873
- error ,
1874
- itemType ,
1875
- asyncPayloadRecord . errors ,
1876
- ) ;
1877
- filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1878
- return handledError ;
1879
- } )
1880
- . then (
1881
- ( value ) => [ value ] ,
1882
- ( error ) => {
1883
- asyncPayloadRecord . errors . push ( error ) ;
1884
- filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
1885
- return null ;
1886
- } ,
1887
- ) ;
1888
-
1889
- asyncPayloadRecord . addItems ( completedItems ) ;
1929
+ asyncPayloadRecord . addItems (
1930
+ completedItemsFromPromisedCompletedItem (
1931
+ exeContext ,
1932
+ itemType ,
1933
+ fieldNodes ,
1934
+ path ,
1935
+ itemPath ,
1936
+ completedItem ,
1937
+ asyncPayloadRecord ,
1938
+ ) ,
1939
+ ) ;
1890
1940
return asyncPayloadRecord ;
1891
1941
}
1892
1942
0 commit comments