Skip to content

Commit

Permalink
incremental delivery rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacovCR committed Apr 5, 2024
1 parent 54858b7 commit 46e4f71
Show file tree
Hide file tree
Showing 10 changed files with 1,709 additions and 1,343 deletions.
992 changes: 501 additions & 491 deletions src/execution/IncrementalPublisher.ts

Large diffs are not rendered by default.

50 changes: 17 additions & 33 deletions src/execution/__tests__/defer-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,20 +367,14 @@ describe('Execute: defer directive', () => {
},
id: '0',
},
],
completed: [{ id: '0' }],
hasNext: true,
},
{
incremental: [
{
data: {
friends: [{ name: 'Han' }, { name: 'Leia' }, { name: 'C-3PO' }],
},
id: '1',
},
],
completed: [{ id: '1' }],
completed: [{ id: '0' }, { id: '1' }],
hasNext: false,
},
]);
Expand Down Expand Up @@ -674,8 +668,8 @@ describe('Execute: defer directive', () => {
hero: {},
},
pending: [
{ id: '0', path: [], label: 'DeferName' },
{ id: '1', path: ['hero'], label: 'DeferID' },
{ id: '0', path: ['hero'], label: 'DeferID' },
{ id: '1', path: [], label: 'DeferName' },
],
hasNext: true,
},
Expand All @@ -685,17 +679,17 @@ describe('Execute: defer directive', () => {
data: {
id: '1',
},
id: '1',
id: '0',
},
{
data: {
name: 'Luke',
},
id: '0',
id: '1',
subPath: ['hero'],
},
],
completed: [{ id: '1' }, { id: '0' }],
completed: [{ id: '0' }, { id: '1' }],
hasNext: false,
},
]);
Expand Down Expand Up @@ -983,37 +977,27 @@ describe('Execute: defer directive', () => {
hasNext: true,
},
{
pending: [{ id: '1', path: ['hero', 'nestedObject'] }],
pending: [
{ id: '1', path: ['hero', 'nestedObject'] },
{ id: '2', path: ['hero', 'nestedObject', 'deeperObject'] },
],
incremental: [
{
data: { bar: 'bar' },
id: '0',
subPath: ['nestedObject', 'deeperObject'],
},
],
completed: [{ id: '0' }],
hasNext: true,
},
{
pending: [{ id: '2', path: ['hero', 'nestedObject', 'deeperObject'] }],
incremental: [
{
data: { baz: 'baz' },
id: '1',
subPath: ['deeperObject'],
},
],
hasNext: true,
completed: [{ id: '1' }],
},
{
incremental: [
{
data: { bak: 'bak' },
id: '2',
},
],
completed: [{ id: '2' }],
completed: [{ id: '0' }, { id: '1' }, { id: '2' }],
hasNext: false,
},
]);
Expand Down Expand Up @@ -1132,23 +1116,23 @@ describe('Execute: defer directive', () => {
},
},
pending: [
{ id: '0', path: [] },
{ id: '1', path: ['a', 'b'] },
{ id: '0', path: ['a', 'b'] },
{ id: '1', path: [] },
],
hasNext: true,
},
{
incremental: [
{
data: { e: { f: 'f' } },
id: '1',
id: '0',
},
{
data: { g: { h: 'h' } },
id: '0',
id: '1',
},
],
completed: [{ id: '1' }, { id: '0' }],
completed: [{ id: '0' }, { id: '1' }],
hasNext: false,
},
]);
Expand Down Expand Up @@ -1277,6 +1261,7 @@ describe('Execute: defer directive', () => {
},
],
completed: [
{ id: '0' },
{
id: '1',
errors: [
Expand All @@ -1288,7 +1273,6 @@ describe('Execute: defer directive', () => {
},
],
},
{ id: '0' },
],
hasNext: false,
},
Expand Down
51 changes: 51 additions & 0 deletions src/execution/__tests__/executor-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,57 @@ describe('Execute: Handles basic execution tasks', () => {
expect(isAsyncResolverFinished).to.equal(true);
});

it('handles async bubbling errors combined with non-bubbling errors', async () => {
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Query',
fields: {
asyncNonNullError: {
type: new GraphQLNonNull(GraphQLString),
async resolve() {
await resolveOnNextTick();
return null;
},
},
asyncError: {
type: GraphQLString,
async resolve() {
await resolveOnNextTick();
throw new Error('Oops');
},
},
},
}),
});

// Order is important here, as the nullable error should resolve first
const document = parse(`
{
asyncError
asyncNonNullError
}
`);

const result = execute({ schema, document });

expectJSON(await result).toDeepEqual({
data: null,
errors: [
{
message: 'Oops',
locations: [{ line: 3, column: 9 }],
path: ['asyncError'],
},
{
message:
'Cannot return null for non-nullable field Query.asyncNonNullError.',
locations: [{ line: 4, column: 9 }],
path: ['asyncNonNullError'],
},
],
});
});

it('Full response path is included for non-nullable fields', () => {
const A: GraphQLObjectType = new GraphQLObjectType({
name: 'A',
Expand Down
2 changes: 2 additions & 0 deletions src/execution/__tests__/nonnull-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ describe('Execute: handles non-nullable types', () => {
path: ['syncNest', 'syncNest', 'sync'],
locations: [{ line: 6, column: 22 }],
},

{
message: promiseError.message,
path: ['syncNest', 'promise'],
Expand All @@ -284,6 +285,7 @@ describe('Execute: handles non-nullable types', () => {
path: ['promiseNest', 'syncNest', 'sync'],
locations: [{ line: 12, column: 22 }],
},

{
message: promiseError.message,
path: ['syncNest', 'promiseNest', 'promise'],
Expand Down
Loading

0 comments on commit 46e4f71

Please sign in to comment.