@@ -39,6 +39,11 @@ const schema = buildSchema(`
3939 leaf: String
4040 }
4141
42+ type Mutation {
43+ first: String
44+ second: String
45+ }
46+
4247 type Subscription {
4348 tick: String
4449 }
@@ -48,11 +53,6 @@ describe('execute diagnostics channel', () => {
4853 let active : ReturnType < typeof collectEvents > | undefined ;
4954 const executeChannel = getTracingChannel ( 'graphql:execute' ) ;
5055
51- const rootValue = {
52- sync : ( ) => 'hello' ,
53- async : ( ) => Promise . resolve ( 'hello-async' ) ,
54- } ;
55-
5656 afterEach ( ( ) => {
5757 active ?. unsubscribe ( ) ;
5858 active = undefined ;
@@ -62,7 +62,11 @@ describe('execute diagnostics channel', () => {
6262 active = collectEvents ( executeChannel ) ;
6363
6464 const document = parse ( 'query Q { sync }' ) ;
65- const result = execute ( { schema, document, rootValue } ) ;
65+ const result = execute ( {
66+ schema,
67+ document,
68+ rootValue : { sync : ( ) => 'hello' } ,
69+ } ) ;
6670
6771 expect ( result ) . to . deep . equal ( { data : { sync : 'hello' } } ) ;
6872 expect ( active . events . map ( ( e ) => e . kind ) ) . to . deep . equal ( [ 'start' , 'end' ] ) ;
@@ -76,7 +80,11 @@ describe('execute diagnostics channel', () => {
7680 active = collectEvents ( executeChannel ) ;
7781
7882 const document = parse ( 'query { async }' ) ;
79- const result = await execute ( { schema, document, rootValue } ) ;
83+ const result = await execute ( {
84+ schema,
85+ document,
86+ rootValue : { async : ( ) => Promise . resolve ( 'hello-async' ) } ,
87+ } ) ;
8088
8189 expect ( result ) . to . deep . equal ( { data : { async : 'hello-async' } } ) ;
8290 expect ( active . events . map ( ( e ) => e . kind ) ) . to . deep . equal ( [
@@ -91,7 +99,7 @@ describe('execute diagnostics channel', () => {
9199 active = collectEvents ( executeChannel ) ;
92100
93101 const document = parse ( '{ sync }' ) ;
94- executeSync ( { schema, document, rootValue } ) ;
102+ executeSync ( { schema, document, rootValue : { sync : ( ) => 'hello' } } ) ;
95103
96104 expect ( active . events . map ( ( e ) => e . kind ) ) . to . deep . equal ( [ 'start' , 'end' ] ) ;
97105 } ) ;
@@ -101,7 +109,11 @@ describe('execute diagnostics channel', () => {
101109
102110 const document = parse ( 'query Q { sync }' ) ;
103111 // eslint-disable-next-line @typescript-eslint/no-floating-promises
104- executeIgnoringIncremental ( { schema, document, rootValue } ) ;
112+ executeIgnoringIncremental ( {
113+ schema,
114+ document,
115+ rootValue : { sync : ( ) => 'hello' } ,
116+ } ) ;
105117
106118 expect ( active . events . map ( ( e ) => e . kind ) ) . to . deep . equal ( [ 'start' , 'end' ] ) ;
107119 expect ( active . events [ 0 ] . ctx . operationName ) . to . equal ( 'Q' ) ;
@@ -115,9 +127,7 @@ describe('execute diagnostics channel', () => {
115127 type Query { sync: String }
116128 ` ) ;
117129 const document = parse ( '{ sync }' ) ;
118- expect ( ( ) =>
119- execute ( { schema : schemaWithDefer , document, rootValue } ) ,
120- ) . to . throw ( ) ;
130+ expect ( ( ) => execute ( { schema : schemaWithDefer , document } ) ) . to . throw ( ) ;
121131
122132 expect ( active . events . map ( ( e ) => e . kind ) ) . to . deep . equal ( [
123133 'start' ,
@@ -165,7 +175,11 @@ describe('execute diagnostics channel', () => {
165175
166176 it ( 'does nothing when no subscribers are attached' , ( ) => {
167177 const document = parse ( '{ sync }' ) ;
168- const result = execute ( { schema, document, rootValue } ) ;
178+ const result = execute ( {
179+ schema,
180+ document,
181+ rootValue : { sync : ( ) => 'hello' } ,
182+ } ) ;
169183 expect ( result ) . to . deep . equal ( { data : { sync : 'hello' } } ) ;
170184 } ) ;
171185} ) ;
@@ -238,7 +252,7 @@ describe('subscribe diagnostics channel', () => {
238252 const document = parse ( 'fragment F on Subscription { tick }' ) ;
239253
240254 // eslint-disable-next-line @typescript-eslint/no-floating-promises
241- subscribe ( { schema, document, rootValue : { tick : twoTicks } } ) ;
255+ subscribe ( { schema, document } ) ;
242256
243257 expect ( active . events . map ( ( e ) => e . kind ) ) . to . deep . equal ( [ 'start' , 'end' ] ) ;
244258 } ) ;
@@ -262,18 +276,6 @@ describe('resolve diagnostics channel', () => {
262276 let active : ReturnType < typeof collectEvents > | undefined ;
263277 const resolveChannel = getTracingChannel ( 'graphql:resolve' ) ;
264278
265- const rootValue = {
266- sync : ( ) => 'hello' ,
267- async : ( ) => Promise . resolve ( 'hello-async' ) ,
268- fail : ( ) => {
269- throw new Error ( 'boom' ) ;
270- } ,
271- asyncFail : ( ) => Promise . reject ( new Error ( 'async-boom' ) ) ,
272- // no `plain` resolver, default property-access is used.
273- plain : 'plain-value' ,
274- nested : { leaf : 'leaf-value' } ,
275- } ;
276-
277279 afterEach ( ( ) => {
278280 active ?. unsubscribe ( ) ;
279281 active = undefined ;
@@ -285,7 +287,7 @@ describe('resolve diagnostics channel', () => {
285287 const result = execute ( {
286288 schema,
287289 document : parse ( '{ sync }' ) ,
288- rootValue,
290+ rootValue : { sync : ( ) => 'hello' } ,
289291 } ) ;
290292 if ( isPromise ( result ) ) {
291293 throw new Error ( 'expected sync' ) ;
@@ -308,7 +310,7 @@ describe('resolve diagnostics channel', () => {
308310 const result = execute ( {
309311 schema,
310312 document : parse ( '{ async }' ) ,
311- rootValue,
313+ rootValue : { async : ( ) => Promise . resolve ( 'hello-async' ) } ,
312314 } ) ;
313315 await result ;
314316
@@ -320,7 +322,15 @@ describe('resolve diagnostics channel', () => {
320322 active = collectEvents ( resolveChannel ) ;
321323
322324 // eslint-disable-next-line @typescript-eslint/no-floating-promises
323- execute ( { schema, document : parse ( '{ fail }' ) , rootValue } ) ;
325+ execute ( {
326+ schema,
327+ document : parse ( '{ fail }' ) ,
328+ rootValue : {
329+ fail : ( ) => {
330+ throw new Error ( 'boom' ) ;
331+ } ,
332+ } ,
333+ } ) ;
324334
325335 const kinds = active . events . map ( ( e ) => e . kind ) ;
326336 expect ( kinds ) . to . deep . equal ( [ 'start' , 'error' , 'end' ] ) ;
@@ -332,7 +342,9 @@ describe('resolve diagnostics channel', () => {
332342 await execute ( {
333343 schema,
334344 document : parse ( '{ asyncFail }' ) ,
335- rootValue,
345+ rootValue : {
346+ asyncFail : ( ) => Promise . reject ( new Error ( 'async-boom' ) ) ,
347+ } ,
336348 } ) ;
337349
338350 const kinds = active . events . map ( ( e ) => e . kind ) ;
@@ -387,7 +399,9 @@ describe('resolve diagnostics channel', () => {
387399 execute ( {
388400 schema,
389401 document : parse ( '{ nested { leaf } }' ) ,
390- rootValue,
402+ rootValue : {
403+ nested : { leaf : 'leaf-value' } ,
404+ } ,
391405 } ) ;
392406
393407 const starts = active . events . filter ( ( e ) => e . kind === 'start' ) ;
@@ -402,7 +416,12 @@ describe('resolve diagnostics channel', () => {
402416 execute ( {
403417 schema,
404418 document : parse ( '{ sync plain nested { leaf } }' ) ,
405- rootValue,
419+ rootValue : {
420+ sync : ( ) => 'hello' ,
421+ // no `plain` resolver, default property-access is used.
422+ plain : 'plain-value' ,
423+ nested : { leaf : 'leaf-value' } ,
424+ } ,
406425 } ) ;
407426
408427 const starts = active . events . filter ( ( e ) => e . kind === 'start' ) ;
@@ -412,25 +431,15 @@ describe('resolve diagnostics channel', () => {
412431 } ) ;
413432
414433 it ( 'emits per-field for serial mutation execution' , async ( ) => {
415- const mutationSchema = new GraphQLSchema ( {
416- query : new GraphQLObjectType ( {
417- name : 'Query' ,
418- fields : { dummy : { type : GraphQLString } } ,
419- } ) ,
420- mutation : new GraphQLObjectType ( {
421- name : 'Mutation' ,
422- fields : {
423- first : { type : GraphQLString , resolve : ( ) => 'one' } ,
424- second : { type : GraphQLString , resolve : ( ) => 'two' } ,
425- } ,
426- } ) ,
427- } ) ;
428-
429434 active = collectEvents ( resolveChannel ) ;
430435
431436 await execute ( {
432- schema : mutationSchema ,
437+ schema,
433438 document : parse ( 'mutation M { first second }' ) ,
439+ rootValue : {
440+ first : ( ) => 'one' ,
441+ second : ( ) => 'two' ,
442+ } ,
434443 } ) ;
435444
436445 const starts = active . events . filter ( ( e ) => e . kind === 'start' ) ;
@@ -444,7 +453,7 @@ describe('resolve diagnostics channel', () => {
444453 const result = execute ( {
445454 schema,
446455 document : parse ( '{ sync }' ) ,
447- rootValue,
456+ rootValue : { sync : ( ) => 'hello' } ,
448457 } ) ;
449458 if ( isPromise ( result ) ) {
450459 throw new Error ( 'expected sync' ) ;
0 commit comments