@@ -1798,6 +1798,78 @@ 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 completedItem = completeValue (
1815
+ exeContext ,
1816
+ itemType ,
1817
+ fieldNodes ,
1818
+ info ,
1819
+ itemPath ,
1820
+ resolved ,
1821
+ asyncPayloadRecord ,
1822
+ ) ;
1823
+ if ( isPromise ( completedItem ) ) {
1824
+ completedItem = await completedItem ;
1825
+ }
1826
+ return [ completedItem ] ;
1827
+ } catch ( rawError ) {
1828
+ const error = locatedError ( rawError , fieldNodes , pathToArray ( itemPath ) ) ;
1829
+ const handledError = handleFieldError (
1830
+ error ,
1831
+ itemType ,
1832
+ asyncPayloadRecord . errors ,
1833
+ ) ;
1834
+ filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1835
+ return [ handledError ] ;
1836
+ }
1837
+ } catch ( error ) {
1838
+ asyncPayloadRecord . errors . push ( error ) ;
1839
+ filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
1840
+ return null ;
1841
+ }
1842
+ }
1843
+
1844
+ async function completedItemsFromPromisedCompletedItem (
1845
+ exeContext : ExecutionContext ,
1846
+ itemType : GraphQLOutputType ,
1847
+ fieldNodes : ReadonlyArray < FieldNode > ,
1848
+ path : Path ,
1849
+ itemPath : Path ,
1850
+ completedItem : Promise < unknown > ,
1851
+ asyncPayloadRecord : AsyncPayloadRecord ,
1852
+ ) : Promise < [ unknown ] | null > {
1853
+ try {
1854
+ try {
1855
+ return [ await completedItem ] ;
1856
+ } catch ( rawError ) {
1857
+ const error = locatedError ( rawError , fieldNodes , pathToArray ( itemPath ) ) ;
1858
+ const handledError = handleFieldError (
1859
+ error ,
1860
+ itemType ,
1861
+ asyncPayloadRecord . errors ,
1862
+ ) ;
1863
+ filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1864
+ return [ handledError ] ;
1865
+ }
1866
+ } catch ( error ) {
1867
+ asyncPayloadRecord . errors . push ( error ) ;
1868
+ filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
1869
+ return null ;
1870
+ }
1871
+ }
1872
+
1801
1873
function executeStreamField (
1802
1874
path : Path ,
1803
1875
itemPath : Path ,
@@ -1816,24 +1888,18 @@ function executeStreamField(
1816
1888
exeContext,
1817
1889
} ) ;
1818
1890
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
- } ,
1891
+ asyncPayloadRecord . addItems (
1892
+ completedItemsFromPromisedItem (
1893
+ exeContext ,
1894
+ itemType ,
1895
+ fieldNodes ,
1896
+ info ,
1897
+ path ,
1898
+ itemPath ,
1899
+ item ,
1900
+ asyncPayloadRecord ,
1901
+ ) ,
1834
1902
) ;
1835
-
1836
- asyncPayloadRecord . addItems ( completedItems ) ;
1837
1903
return asyncPayloadRecord ;
1838
1904
}
1839
1905
@@ -1866,27 +1932,17 @@ function executeStreamField(
1866
1932
}
1867
1933
1868
1934
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 ) ;
1935
+ asyncPayloadRecord . addItems (
1936
+ completedItemsFromPromisedCompletedItem (
1937
+ exeContext ,
1938
+ itemType ,
1939
+ fieldNodes ,
1940
+ path ,
1941
+ itemPath ,
1942
+ completedItem ,
1943
+ asyncPayloadRecord ,
1944
+ ) ,
1945
+ ) ;
1890
1946
return asyncPayloadRecord ;
1891
1947
}
1892
1948
0 commit comments