Skip to content

Commit

Permalink
add a few more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacovCR committed Jul 8, 2024
1 parent ed27153 commit 728457a
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 0 deletions.
74 changes: 74 additions & 0 deletions packages/executor/src/execution/__tests__/defer-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1638,6 +1638,80 @@ describe('Execute: defer directive', () => {
]);
});

it('Nulls do not cross defer boundaries, when using branching executor format', async () => {
const document = parse(`
query {
... @defer {
a {
someField
b {
c {
nonNullErrorField
}
}
}
}
a {
... @defer {
b {
c {
d
}
}
}
}
}
`);
const result = await complete(
document,
{
a: { b: { c: { d: 'd' } }, someField: 'someField' },
},
undefined,
false,
);
expectJSON(result).toDeepEqual([
{
data: {
a: {},
},
pending: [
{ id: '0', path: ['a'] },
{ id: '1', path: [] },
],
hasNext: true,
},
{
incremental: [
{
data: { b: { c: { d: 'd' } } },
id: '0',
path: ['a'],
},
{
data: { a: { someField: 'someField', b: { c: null } } },
errors: [
{
message: 'Cannot return null for non-nullable field c.nonNullErrorField.',
locations: [{ line: 8, column: 17 }],
path: ['a', 'b', 'c', 'nonNullErrorField'],
},
],
id: '1',
path: [],
},
],
completed: [
{
id: '0',
},
{ id: '1' },
],
hasNext: false,
},
]);
});

it('Nulls cross defer boundaries, value first', async () => {
const document = parse(`
query {
Expand Down
73 changes: 73 additions & 0 deletions packages/executor/src/execution/__tests__/stream-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,15 @@ async function complete(
document: DocumentNode,
rootValue: unknown = {},
enableEarlyExecution = false,
useLatestFormat = true,
) {
const result = await execute({
schema,
document,
rootValue,
enableEarlyExecution,
sendIncrementalErrorsAsNull: !useLatestFormat,
sendPathAndLabelOnIncremental: !useLatestFormat,
});

if ('initialResult' in result) {
Expand Down Expand Up @@ -144,6 +147,31 @@ describe('Execute: stream directive', () => {
},
]);
});
it('Can stream a list field using branching executor format', async () => {
const document = parse('{ scalarList @stream(initialCount: 1) }');
const result = await complete(
document,
{
scalarList: () => ['apple', 'banana', 'coconut'],
},
undefined,
false,
);
expectJSON(result).toDeepEqual([
{
data: {
scalarList: ['apple'],
},
pending: [{ id: '0', path: ['scalarList'] }],
hasNext: true,
},
{
incremental: [{ items: ['banana', 'coconut'], id: '0', path: ['scalarList', 1] }],
completed: [{ id: '0' }],
hasNext: false,
},
]);
});
it('Can use default value of initialCount', async () => {
const document = parse('{ scalarList @stream }');
const result = await complete(document, {
Expand Down Expand Up @@ -1020,6 +1048,51 @@ describe('Execute: stream directive', () => {
},
]);
});
it('Handles null returned in non-null list items after initialCount is reached, using branching executor format', async () => {
const document = parse(/* GraphQL */ `
query {
nonNullFriendList @stream(initialCount: 1) {
name
}
}
`);
const result = await complete(
document,
{
nonNullFriendList: () => [friends[0], null, friends[1]],
},
undefined,
false,
);

expectJSON(result).toDeepEqual([
{
data: {
nonNullFriendList: [{ name: 'Luke' }],
},
pending: [{ id: '0', path: ['nonNullFriendList'] }],
hasNext: true,
},
{
incremental: [
{
errors: [
{
message: 'Cannot return null for non-nullable field Query.nonNullFriendList.',
locations: [{ line: 3, column: 9 }],
path: ['nonNullFriendList', 1],
},
],
items: null,
id: '0',
path: ['nonNullFriendList', 1],
},
],
completed: [{ id: '0' }],
hasNext: false,
},
]);
});
it('Handles null returned in non-null async iterable list items after initialCount is reached', async () => {
const document = parse(/* GraphQL */ `
query {
Expand Down

0 comments on commit 728457a

Please sign in to comment.