Skip to content

feat(incremental): do not initiate multiple streams at the same path #3830

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

Closed
wants to merge 8 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
425 changes: 405 additions & 20 deletions src/execution/__tests__/defer-test.ts

Large diffs are not rendered by default.

43 changes: 27 additions & 16 deletions src/execution/__tests__/executor-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import { expectJSON } from '../../__testUtils__/expectJSON.js';
import { resolveOnNextTick } from '../../__testUtils__/resolveOnNextTick.js';

import { inspect } from '../../jsutils/inspect.js';
import type { Path } from '../../jsutils/Path.js';

import { Kind } from '../../language/kinds.js';
import { parse } from '../../language/parser.js';

import type { GraphQLResolveInfo } from '../../type/definition.js';
import {
GraphQLInterfaceType,
GraphQLList,
Expand Down Expand Up @@ -191,7 +193,7 @@ describe('Execute: Handles basic execution tasks', () => {
});

it('provides info about current execution state', () => {
let resolvedInfo;
let resolvedInfo: GraphQLResolveInfo | undefined;
const testType = new GraphQLObjectType({
name: 'Test',
fields: {
Expand All @@ -213,7 +215,8 @@ describe('Execute: Handles basic execution tasks', () => {

expect(resolvedInfo).to.have.all.keys(
'fieldName',
'fieldNodes',
'fieldGroup',
'deferDepth',
'returnType',
'parentType',
'path',
Expand All @@ -236,16 +239,22 @@ describe('Execute: Handles basic execution tasks', () => {
operation,
});

const field = operation.selectionSet.selections[0];
const fieldNode = operation.selectionSet.selections[0];
expect(resolvedInfo).to.deep.include({
fieldNodes: [field],
path: { prev: undefined, key: 'result', typename: 'Test' },
fieldGroup: [{ fieldNode, depth: 0, deferDepth: undefined }],
deferDepth: undefined,
variableValues: { var: 'abc' },
});

expect(resolvedInfo?.path).to.deep.include({
prev: undefined,
key: 'result',
typename: 'Test',
});
});

it('populates path correctly with complex types', () => {
let path;
let path: Path | undefined;
const someObject = new GraphQLObjectType({
name: 'SomeObject',
fields: {
Expand Down Expand Up @@ -288,18 +297,20 @@ describe('Execute: Handles basic execution tasks', () => {

executeSync({ schema, document, rootValue });

expect(path).to.deep.equal({
expect(path).to.deep.include({
key: 'l2',
typename: 'SomeObject',
prev: {
key: 0,
typename: undefined,
prev: {
key: 'l1',
typename: 'SomeQuery',
prev: undefined,
},
},
});

expect(path?.prev).to.deep.include({
key: 0,
typename: undefined,
});

expect(path?.prev?.prev).to.deep.include({
key: 'l1',
typename: 'SomeQuery',
prev: undefined,
});
});

Expand Down
6 changes: 2 additions & 4 deletions src/execution/__tests__/mutations-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ describe('Execute: Handles mutation execution ordering', () => {
const document = parse(`
mutation M {
first: promiseToChangeTheNumber(newNumber: 1) {
...DeferFragment @defer(label: "defer-label")
...DeferFragment @defer
},
second: immediatelyChangeTheNumber(newNumber: 2) {
theNumber
Expand Down Expand Up @@ -242,7 +242,6 @@ describe('Execute: Handles mutation execution ordering', () => {
{
incremental: [
{
label: 'defer-label',
path: ['first'],
data: {
promiseToGetTheNumber: 2,
Expand Down Expand Up @@ -281,7 +280,7 @@ describe('Execute: Handles mutation execution ordering', () => {
it('Mutation with @defer is not executed serially', async () => {
const document = parse(`
mutation M {
...MutationFragment @defer(label: "defer-label")
...MutationFragment @defer
second: immediatelyChangeTheNumber(newNumber: 2) {
theNumber
}
Expand Down Expand Up @@ -317,7 +316,6 @@ describe('Execute: Handles mutation execution ordering', () => {
{
incremental: [
{
label: 'defer-label',
path: [],
data: {
first: {
Expand Down
Loading