Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incremental: remove filtering from rewrite #4032

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
998 changes: 508 additions & 490 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