@@ -1798,6 +1798,78 @@ function executeDeferredFragment(
17981798 asyncPayloadRecord . addData ( promiseOrData ) ;
17991799}
18001800
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+
18011873function executeStreamField (
18021874 path : Path ,
18031875 itemPath : Path ,
@@ -1816,24 +1888,18 @@ function executeStreamField(
18161888 exeContext,
18171889 } ) ;
18181890 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+ ) ,
18341902 ) ;
1835-
1836- asyncPayloadRecord . addItems ( completedItems ) ;
18371903 return asyncPayloadRecord ;
18381904 }
18391905
@@ -1866,27 +1932,17 @@ function executeStreamField(
18661932 }
18671933
18681934 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+ ) ;
18901946 return asyncPayloadRecord ;
18911947 }
18921948
0 commit comments