@@ -54,23 +54,27 @@ export class BatchedGraphQLClient {
5454
5555 const results = await getResults ( response )
5656
57- if ( Array . isArray ( results ) ) {
58- const allResultsHaveData =
59- results . filter ( r => r . data ) . length === results . length
60-
61- if ( response . ok && ! results . find ( r => r . errors ) && allResultsHaveData ) {
62- return results . map ( r => r . data )
63- } else {
64- const errorIndex = results . findIndex ( r => r . errors )
65- const result = results [ errorIndex ]
66- const errorResult =
67- typeof result === 'string' ? { error : result } : result
68- throw new ClientError ( { ...errorResult , status : response . status } )
69- }
70- } else {
71- // if it is not an array, there must be an error
57+ // if it is not an array, there must be an error
58+ if ( ! Array . isArray ( results ) ) {
7259 throw new ClientError ( { ...results , status : response . status } )
7360 }
61+
62+ // check if there was an error in one of the responses
63+ if (
64+ ! response . ok ||
65+ results . some ( r => r . errors !== undefined || r . data === undefined )
66+ ) {
67+ const errorIndex = results . findIndex (
68+ r => r . errors !== undefined || r . data === undefined ,
69+ )
70+ const result = results [ errorIndex ]
71+ const errorResult =
72+ typeof result === 'string' ? { errors : [ { message : result } ] } : result
73+
74+ throw new ClientError ( { ...errorResult , status : response . status } )
75+ }
76+
77+ return results . map ( r => r . data )
7478 }
7579}
7680
0 commit comments