Skip to content

Commit 233a96e

Browse files
committed
apply review feedback
1 parent f6772f9 commit 233a96e

File tree

1 file changed

+72
-40
lines changed

1 file changed

+72
-40
lines changed

src/execution/__tests__/defer-test.ts

Lines changed: 72 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,25 @@ const friends = [
3939

4040
const deeperObject = new GraphQLObjectType({
4141
fields: {
42-
foo: { type: GraphQLString, resolve: () => 'foo' },
43-
bar: { type: GraphQLString, resolve: () => 'bar' },
44-
baz: { type: GraphQLString, resolve: () => 'baz' },
45-
bak: { type: GraphQLString, resolve: () => 'bak' },
42+
foo: { type: GraphQLString },
43+
bar: { type: GraphQLString },
44+
baz: { type: GraphQLString },
45+
bak: { type: GraphQLString },
4646
},
4747
name: 'DeeperObject',
4848
});
4949

5050
const nestedObject = new GraphQLObjectType({
5151
fields: {
52-
deeperObject: { type: deeperObject, resolve: () => ({}) },
53-
name: { type: GraphQLString, resolve: () => 'foo' },
52+
deeperObject: { type: deeperObject },
53+
name: { type: GraphQLString },
5454
},
5555
name: 'NestedObject',
5656
});
5757

5858
const anotherNestedObject = new GraphQLObjectType({
5959
fields: {
60-
deeperObject: { type: deeperObject, resolve: () => ({}) },
60+
deeperObject: { type: deeperObject },
6161
},
6262
name: 'AnotherNestedObject',
6363
});
@@ -72,48 +72,38 @@ const hero = {
7272

7373
const c = new GraphQLObjectType({
7474
fields: {
75-
d: { type: GraphQLString, resolve: () => 'd' },
76-
nonNullErrorField: {
77-
type: new GraphQLNonNull(GraphQLString),
78-
resolve: () => null,
79-
},
80-
slowNonNullErrorField: {
81-
type: new GraphQLNonNull(GraphQLString),
82-
resolve: async () => {
83-
await resolveOnNextTick();
84-
return null;
85-
},
86-
},
75+
d: { type: GraphQLString },
76+
nonNullErrorField: { type: new GraphQLNonNull(GraphQLString) },
8777
},
8878
name: 'c',
8979
});
9080

9181
const e = new GraphQLObjectType({
9282
fields: {
93-
f: { type: GraphQLString, resolve: () => 'f' },
83+
f: { type: GraphQLString },
9484
},
9585
name: 'e',
9686
});
9787

9888
const b = new GraphQLObjectType({
9989
fields: {
100-
c: { type: c, resolve: () => ({}) },
101-
e: { type: e, resolve: () => ({}) },
90+
c: { type: c },
91+
e: { type: e },
10292
},
10393
name: 'b',
10494
});
10595

10696
const a = new GraphQLObjectType({
10797
fields: {
108-
b: { type: b, resolve: () => ({}) },
109-
someField: { type: GraphQLString, resolve: () => 'someField' },
98+
b: { type: b },
99+
someField: { type: GraphQLString },
110100
},
111101
name: 'a',
112102
});
113103

114104
const g = new GraphQLObjectType({
115105
fields: {
116-
h: { type: GraphQLString, resolve: () => 'h' },
106+
h: { type: GraphQLString },
117107
},
118108
name: 'g',
119109
});
@@ -137,8 +127,8 @@ const query = new GraphQLObjectType({
137127
hero: {
138128
type: heroType,
139129
},
140-
a: { type: a, resolve: () => ({}) },
141-
g: { type: g, resolve: () => ({}) },
130+
a: { type: a },
131+
g: { type: g },
142132
},
143133
name: 'Query',
144134
});
@@ -782,7 +772,12 @@ describe('Execute: defer directive', () => {
782772
}
783773
}
784774
`);
785-
const result = await complete(document);
775+
const result = await complete(document, {
776+
hero: {
777+
nestedObject: { deeperObject: { foo: 'foo', bar: 'bar' } },
778+
anotherNestedObject: { deeperObject: { foo: 'foo' } },
779+
},
780+
});
786781
expectJSON(result).toDeepEqual([
787782
{
788783
data: {
@@ -842,7 +837,9 @@ describe('Execute: defer directive', () => {
842837
}
843838
}
844839
`);
845-
const result = await complete(document);
840+
const result = await complete(document, {
841+
hero: { nestedObject: { deeperObject: { foo: 'foo', bar: 'bar' } } },
842+
});
846843
expectJSON(result).toDeepEqual([
847844
{
848845
data: {
@@ -913,7 +910,13 @@ describe('Execute: defer directive', () => {
913910
}
914911
}
915912
`);
916-
const result = await complete(document);
913+
const result = await complete(document, {
914+
hero: {
915+
nestedObject: {
916+
deeperObject: { foo: 'foo', bar: 'bar', baz: 'baz', bak: 'bak' },
917+
},
918+
},
919+
});
917920
expectJSON(result).toDeepEqual([
918921
{
919922
data: {
@@ -999,7 +1002,9 @@ describe('Execute: defer directive', () => {
9991002
}
10001003
}
10011004
`);
1002-
const result = await complete(document);
1005+
const result = await complete(document, {
1006+
hero: { nestedObject: { deeperObject: { foo: 'foo', bar: 'bar' } } },
1007+
});
10031008
expectJSON(result).toDeepEqual([
10041009
{
10051010
data: {
@@ -1074,7 +1079,15 @@ describe('Execute: defer directive', () => {
10741079
}
10751080
}
10761081
`);
1077-
const result = await complete(document);
1082+
const result = await complete(document, {
1083+
a: {
1084+
b: {
1085+
c: { d: 'd' },
1086+
e: { f: 'f' },
1087+
},
1088+
},
1089+
g: { h: 'h' },
1090+
});
10781091
expectJSON(result).toDeepEqual([
10791092
{
10801093
data: {
@@ -1143,7 +1156,9 @@ describe('Execute: defer directive', () => {
11431156
}
11441157
}
11451158
`);
1146-
const result = await complete(document);
1159+
const result = await complete(document, {
1160+
a: { b: { c: { d: 'd' } }, someField: 'someField' },
1161+
});
11471162
expectJSON(result).toDeepEqual([
11481163
{
11491164
data: {
@@ -1212,7 +1227,12 @@ describe('Execute: defer directive', () => {
12121227
}
12131228
}
12141229
`);
1215-
const result = await complete(document);
1230+
const result = await complete(document, {
1231+
a: {
1232+
b: { c: { d: 'd' }, nonNullErrorFIeld: null },
1233+
someField: 'someField',
1234+
},
1235+
});
12161236
expectJSON(result).toDeepEqual([
12171237
{
12181238
data: {
@@ -1265,7 +1285,7 @@ describe('Execute: defer directive', () => {
12651285
someField
12661286
b {
12671287
c {
1268-
slowNonNullErrorField
1288+
nonNullErrorField
12691289
}
12701290
}
12711291
}
@@ -1281,7 +1301,20 @@ describe('Execute: defer directive', () => {
12811301
}
12821302
}
12831303
`);
1284-
const result = await complete(document);
1304+
const result = await complete(document, {
1305+
a: {
1306+
b: {
1307+
c: {
1308+
d: 'd',
1309+
nonNullErrorField: async () => {
1310+
await resolveOnNextTick();
1311+
return null;
1312+
},
1313+
},
1314+
},
1315+
someField: 'someField',
1316+
},
1317+
});
12851318
expectJSON(result).toDeepEqual([
12861319
{
12871320
data: {
@@ -1318,9 +1351,9 @@ describe('Execute: defer directive', () => {
13181351
errors: [
13191352
{
13201353
message:
1321-
'Cannot return null for non-nullable field c.slowNonNullErrorField.',
1354+
'Cannot return null for non-nullable field c.nonNullErrorField.',
13221355
locations: [{ line: 8, column: 17 }],
1323-
path: ['a', 'b', 'c', 'slowNonNullErrorField'],
1356+
path: ['a', 'b', 'c', 'nonNullErrorField'],
13241357
},
13251358
],
13261359
path: [],
@@ -1677,8 +1710,7 @@ describe('Execute: defer directive', () => {
16771710
`);
16781711
const result = await complete(document, {
16791712
hero: {
1680-
...hero,
1681-
nestedObject: () => Promise.resolve({}),
1713+
nestedObject: () => Promise.resolve({ name: 'foo' }),
16821714
},
16831715
});
16841716
expectJSON(result).toDeepEqual([

0 commit comments

Comments
 (0)