diff --git a/src/index.ts b/src/index.ts index 31dfbec0c..8a0d8ec37 100644 --- a/src/index.ts +++ b/src/index.ts @@ -482,7 +482,10 @@ async function makeRequest({ isBatchingQuery && Array.isArray(result) ? !result.some(({ data }) => !data) : !!result.data const successfullyPassedErrorPolicy = - !result.errors || fetchOptions.errorPolicy === 'all' || fetchOptions.errorPolicy === 'ignore' + !result.errors || + (Array.isArray(result.errors) && !result.errors.length) || + fetchOptions.errorPolicy === 'all' || + fetchOptions.errorPolicy === 'ignore' if (response.ok && successfullyPassedErrorPolicy && successfullyReceivedData) { const { headers, status } = response diff --git a/tests/__helpers.ts b/tests/__helpers.ts index 1d598717a..38a6662dc 100644 --- a/tests/__helpers.ts +++ b/tests/__helpers.ts @@ -3,7 +3,7 @@ import body from 'body-parser' import express, { Application, Request } from 'express' import getPort from 'get-port' import { createServer, Server } from 'http' -import { JsonObject } from 'type-fest' +import { JsonArray, JsonObject } from 'type-fest' import { beforeAll, afterEach, afterAll, beforeEach } from 'vitest' type CapturedRequest = Pick @@ -21,7 +21,7 @@ type Context = { type MockSpecBody = { data?: JsonObject extensions?: JsonObject - errors?: JsonObject + errors?: JsonObject | JsonArray } type MockSpec = { diff --git a/tests/general.test.ts b/tests/general.test.ts index f96f4e61f..e31f08444 100644 --- a/tests/general.test.ts +++ b/tests/general.test.ts @@ -396,3 +396,16 @@ describe('operationName parsing', () => { expect(requestBody.operationName).toEqual('myStringOperation') }) }) + +test('should not throw error when errors property is an empty array (occured when using UltraGraphQL)', async () => { + ctx.res({ + body: { + data: { test: 'test' }, + errors: [], + }, + }) + + const res = await new GraphQLClient(ctx.url).request(`{ test }`) + + expect(res).toEqual(expect.objectContaining({ test: 'test' })) +})