Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/batch-execute/src/splitResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ export function splitResult(
{ data, errors }: ExecutionResult,
numResults: number,
): Array<ExecutionResult> {
const splitResults = new Array<ExecutionResult>(numResults);
const splitResults: ExecutionResult[] = Array.from(
{ length: numResults },
() => ({ data: null }),
);

if (data) {
for (const prefixedKey in data) {
Expand Down
32 changes: 32 additions & 0 deletions packages/batch-execute/tests/batchExecute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
field1: String
field2: String
field3(input: String): String
fieldNonNullable: String!
boom(message: String): String
boomNonNullable(message: String): String!
boomWithPath(message: String, path: [String]): String
extension: String
widget: Widget
Expand All @@ -37,6 +39,7 @@
field2: () => '2',
field3: (_root, { input }) => String(input),
boom: (_root, { message }) => new Error(message),
boomNonNullable: (_root, { message }) => new Error(message),
boomWithPath: (_root, { message, path }) =>
createGraphQLError(message, { path }),
extension: () => createGraphQLError('boom', { extensions }),
Expand Down Expand Up @@ -231,6 +234,35 @@
expect(executorCalls).toEqual(1);
});

it('returns error for the failing non-nullable field', async () => {
const [first] = (await Promise.all([
batchExec({
document: parse(
'{ fieldNonNullable boomNonNullable(message: "failed") }',
),
}),
])) as ExecutionResult[];

expect(first?.data).toBeNull();
expect(first?.errors?.length).toEqual(1);
expect(first?.errors?.[0]?.message).toMatch(/failed/);

Check failure on line 248 in packages/batch-execute/tests/batchExecute.test.ts

View workflow job for this annotation

GitHub Actions / Unit / Node v22

packages/batch-execute/tests/batchExecute.test.ts > batch execution > returns error for the failing non-nullable field

AssertionError: expected 'Cannot return null for non-nullable f…' to match /failed/ - Expected: /failed/ + Received: "Cannot return null for non-nullable field Query.fieldNonNullable." ❯ packages/batch-execute/tests/batchExecute.test.ts:248:41

Check failure on line 248 in packages/batch-execute/tests/batchExecute.test.ts

View workflow job for this annotation

GitHub Actions / Unit / Node v18

packages/batch-execute/tests/batchExecute.test.ts > batch execution > returns error for the failing non-nullable field

AssertionError: expected 'Cannot return null for non-nullable f…' to match /failed/ - Expected: /failed/ + Received: "Cannot return null for non-nullable field Query.fieldNonNullable." ❯ packages/batch-execute/tests/batchExecute.test.ts:248:41

Check failure on line 248 in packages/batch-execute/tests/batchExecute.test.ts

View workflow job for this annotation

GitHub Actions / Unit / Node v24

packages/batch-execute/tests/batchExecute.test.ts > batch execution > returns error for the failing non-nullable field

AssertionError: expected 'Cannot return null for non-nullable f…' to match /failed/ - Expected: /failed/ + Received: "Cannot return null for non-nullable field Query.fieldNonNullable." ❯ packages/batch-execute/tests/batchExecute.test.ts:248:41

Check failure on line 248 in packages/batch-execute/tests/batchExecute.test.ts

View workflow job for this annotation

GitHub Actions / Unit / Node v20

packages/batch-execute/tests/batchExecute.test.ts > batch execution > returns error for the failing non-nullable field

AssertionError: expected 'Cannot return null for non-nullable f…' to match /failed/ - Expected: /failed/ + Received: "Cannot return null for non-nullable field Query.fieldNonNullable." ❯ packages/batch-execute/tests/batchExecute.test.ts:248:41

Check failure on line 248 in packages/batch-execute/tests/batchExecute.test.ts

View workflow job for this annotation

GitHub Actions / Unit / Node v23

packages/batch-execute/tests/batchExecute.test.ts > batch execution > returns error for the failing non-nullable field

AssertionError: expected 'Cannot return null for non-nullable f…' to match /failed/ - Expected: /failed/ + Received: "Cannot return null for non-nullable field Query.fieldNonNullable." ❯ packages/batch-execute/tests/batchExecute.test.ts:248:41

Check failure on line 248 in packages/batch-execute/tests/batchExecute.test.ts

View workflow job for this annotation

GitHub Actions / Unit / Bun

error: expect(received).toMatch(expected)

Expected substring or pattern: /failed/ Received: "Cannot return null for non-nullable field Query.fieldNonNullable." at <anonymous> (/home/runner/work/gateway/gateway/packages/batch-execute/tests/batchExecute.test.ts:248:41)

Check failure on line 248 in packages/batch-execute/tests/batchExecute.test.ts

View workflow job for this annotation

GitHub Actions / Unit / Bun

error: expect(received).toMatch(expected)

Expected substring or pattern: /failed/ Received: "Cannot return null for non-nullable field Query.fieldNonNullable." at <anonymous> (/home/runner/work/gateway/gateway/packages/batch-execute/tests/batchExecute.test.ts:248:41)

Check failure on line 248 in packages/batch-execute/tests/batchExecute.test.ts

View workflow job for this annotation

GitHub Actions / Unit / Bun

error: expect(received).toMatch(expected)

Expected substring or pattern: /failed/ Received: "Cannot return null for non-nullable field Query.fieldNonNullable." at <anonymous> (/home/runner/work/gateway/gateway/packages/batch-execute/tests/batchExecute.test.ts:248:41)
expect(executorCalls).toEqual(1);
});

it('returns error for the failing non-nullable field across multiple executions', async () => {
const [first, second] = (await Promise.all([
batchExec({ document: parse('{ fieldNonNullable }') }),
batchExec({ document: parse('{ boomNonNullable(message: "failed") }') }),
])) as ExecutionResult[];

expect(first?.data).toBeNull();
expect(first?.errors).toBeUndefined();

Check failure on line 259 in packages/batch-execute/tests/batchExecute.test.ts

View workflow job for this annotation

GitHub Actions / Unit / Node v22

packages/batch-execute/tests/batchExecute.test.ts > batch execution > returns error for the failing non-nullable field across multiple executions

AssertionError: expected [ GraphQLError{ …(10) } ] to be undefined - Expected: undefined + Received: [ GraphQLError { "message": "Cannot return null for non-nullable field Query.fieldNonNullable.", "path": [ "fieldNonNullable", ], "locations": [ { "column": 3, "line": 1, }, ], "extensions": {}, }, ] ❯ packages/batch-execute/tests/batchExecute.test.ts:259:27

Check failure on line 259 in packages/batch-execute/tests/batchExecute.test.ts

View workflow job for this annotation

GitHub Actions / Unit / Node v18

packages/batch-execute/tests/batchExecute.test.ts > batch execution > returns error for the failing non-nullable field across multiple executions

AssertionError: expected [ GraphQLError{ …(10) } ] to be undefined - Expected: undefined + Received: [ GraphQLError { "message": "Cannot return null for non-nullable field Query.fieldNonNullable.", "path": [ "fieldNonNullable", ], "locations": [ { "column": 3, "line": 1, }, ], "extensions": {}, }, ] ❯ packages/batch-execute/tests/batchExecute.test.ts:259:27

Check failure on line 259 in packages/batch-execute/tests/batchExecute.test.ts

View workflow job for this annotation

GitHub Actions / Unit / Node v24

packages/batch-execute/tests/batchExecute.test.ts > batch execution > returns error for the failing non-nullable field across multiple executions

AssertionError: expected [ GraphQLError{ …(10) } ] to be undefined - Expected: undefined + Received: [ GraphQLError { "message": "Cannot return null for non-nullable field Query.fieldNonNullable.", "path": [ "fieldNonNullable", ], "locations": [ { "column": 3, "line": 1, }, ], "extensions": {}, }, ] ❯ packages/batch-execute/tests/batchExecute.test.ts:259:27

Check failure on line 259 in packages/batch-execute/tests/batchExecute.test.ts

View workflow job for this annotation

GitHub Actions / Unit / Node v20

packages/batch-execute/tests/batchExecute.test.ts > batch execution > returns error for the failing non-nullable field across multiple executions

AssertionError: expected [ GraphQLError{ …(10) } ] to be undefined - Expected: undefined + Received: [ GraphQLError { "message": "Cannot return null for non-nullable field Query.fieldNonNullable.", "path": [ "fieldNonNullable", ], "locations": [ { "column": 3, "line": 1, }, ], "extensions": {}, }, ] ❯ packages/batch-execute/tests/batchExecute.test.ts:259:27

Check failure on line 259 in packages/batch-execute/tests/batchExecute.test.ts

View workflow job for this annotation

GitHub Actions / Unit / Node v23

packages/batch-execute/tests/batchExecute.test.ts > batch execution > returns error for the failing non-nullable field across multiple executions

AssertionError: expected [ GraphQLError{ …(10) } ] to be undefined - Expected: undefined + Received: [ GraphQLError { "message": "Cannot return null for non-nullable field Query.fieldNonNullable.", "path": [ "fieldNonNullable", ], "locations": [ { "column": 3, "line": 1, }, ], "extensions": {}, }, ] ❯ packages/batch-execute/tests/batchExecute.test.ts:259:27
expect(second?.data).toBeNull();
expect(second?.errors?.length).toEqual(1);
expect(second?.errors?.[0]?.message).toMatch(/failed/);
expect(executorCalls).toEqual(1);
});

it('pathed errors contain extensions', async () => {
const [first] = (await Promise.all([
batchExec({ document: parse('{ extension }') }),
Expand Down
Loading