Skip to content
657 changes: 619 additions & 38 deletions src/execution/__tests__/defer-test.ts

Large diffs are not rendered by default.

53 changes: 34 additions & 19 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 @@ -227,25 +230,35 @@ describe('Execute: Handles basic execution tasks', () => {
const operation = document.definitions[0];
assert(operation.kind === Kind.OPERATION_DEFINITION);

expect(resolvedInfo).to.include({
expect(resolvedInfo).to.deep.include({
fieldName: 'test',
returnType: GraphQLString,
parentType: testType,
schema,
rootValue,
operation,
deferDepth: undefined,
variableValues: { var: 'abc' },
});

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

const fieldNode = operation.selectionSet.selections[0];
expect(resolvedInfo?.fieldGroup.fields.get(undefined)).to.deep.equal([
fieldNode,
]);

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 +301,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
30 changes: 5 additions & 25 deletions src/execution/__tests__/stream-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,7 @@ describe('Execute: stream directive', () => {
});
});
it('Returns label from stream directive', async () => {
const document = parse(
'{ scalarList @stream(initialCount: 1, label: "scalar-stream") }',
);
const document = parse('{ scalarList @stream(initialCount: 1) }');
const result = await complete(document, {
scalarList: () => ['apple', 'banana', 'coconut'],
});
Expand All @@ -228,7 +226,6 @@ describe('Execute: stream directive', () => {
{
items: ['banana'],
path: ['scalarList', 1],
label: 'scalar-stream',
},
],
hasNext: true,
Expand All @@ -238,7 +235,6 @@ describe('Execute: stream directive', () => {
{
items: ['coconut'],
path: ['scalarList', 2],
label: 'scalar-stream',
},
],
hasNext: false,
Expand Down Expand Up @@ -531,11 +527,6 @@ describe('Execute: stream directive', () => {
},
],
},
],
hasNext: true,
},
{
incremental: [
{
items: [{ name: 'Leia', id: '3' }],
path: ['friendList', 2],
Expand Down Expand Up @@ -984,11 +975,6 @@ describe('Execute: stream directive', () => {
},
],
},
],
hasNext: true,
},
{
incremental: [
{
items: [{ nonNullName: 'Han' }],
path: ['friendList', 2],
Expand Down Expand Up @@ -1661,8 +1647,8 @@ describe('Execute: stream directive', () => {

const document = parse(`
query {
friendList @stream(initialCount: 1, label:"stream-label") {
...NameFragment @defer(label: "DeferName") @defer(label: "DeferName")
friendList @stream(initialCount: 1) {
...NameFragment @defer
id
}
}
Expand Down Expand Up @@ -1705,12 +1691,10 @@ describe('Execute: stream directive', () => {
{
data: { name: 'Luke' },
path: ['friendList', 0],
label: 'DeferName',
},
{
items: [{ id: '2' }],
path: ['friendList', 1],
label: 'stream-label',
},
],
hasNext: true,
Expand All @@ -1727,7 +1711,6 @@ describe('Execute: stream directive', () => {
{
data: { name: 'Han' },
path: ['friendList', 1],
label: 'DeferName',
},
],
hasNext: false,
Expand All @@ -1747,8 +1730,8 @@ describe('Execute: stream directive', () => {

const document = parse(`
query {
friendList @stream(initialCount: 1, label:"stream-label") {
...NameFragment @defer(label: "DeferName") @defer(label: "DeferName")
friendList @stream(initialCount: 1) {
...NameFragment @defer
id
}
}
Expand Down Expand Up @@ -1791,12 +1774,10 @@ describe('Execute: stream directive', () => {
{
data: { name: 'Luke' },
path: ['friendList', 0],
label: 'DeferName',
},
{
items: [{ id: '2' }],
path: ['friendList', 1],
label: 'stream-label',
},
],
hasNext: true,
Expand All @@ -1811,7 +1792,6 @@ describe('Execute: stream directive', () => {
{
data: { name: 'Han' },
path: ['friendList', 1],
label: 'DeferName',
},
],
hasNext: true,
Expand Down
2 changes: 1 addition & 1 deletion src/execution/__tests__/sync-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ describe('Execute: synchronously when possible', () => {
it('throws if encountering async iterable execution', () => {
const doc = `
query Example {
...deferFrag @defer(label: "deferLabel")
...deferFrag @defer
}
fragment deferFrag on Query {
syncField
Expand Down
Loading