@@ -14,7 +14,7 @@ import { GraphQLList, GraphQLObjectType } from '../../type/definition';
14
14
import { GraphQLBoolean , GraphQLInt , GraphQLString } from '../../type/scalars' ;
15
15
import { GraphQLSchema } from '../../type/schema' ;
16
16
17
- import type { ExecutionResult } from '../execute' ;
17
+ import type { ExecutionArgs , ExecutionResult } from '../execute' ;
18
18
import { createSourceEventStream , subscribe } from '../execute' ;
19
19
20
20
import { SimplePubSub } from './simplePubSub' ;
@@ -195,6 +195,15 @@ function subscribeWithBadFn(
195
195
) ;
196
196
}
197
197
198
+ function subscribeWithBadArgs (
199
+ args : ExecutionArgs ,
200
+ ) : PromiseOrValue < ExecutionResult | AsyncIterable < unknown > > {
201
+ return expectEqualPromisesOrValues (
202
+ subscribe ( args ) ,
203
+ createSourceEventStream ( args ) ,
204
+ ) ;
205
+ }
206
+
198
207
/* eslint-disable @typescript-eslint/require-await */
199
208
// Check all error cases when initializing the subscription.
200
209
describe ( 'Subscription Initialization Phase' , ( ) => {
@@ -403,29 +412,31 @@ describe('Subscription Initialization Phase', () => {
403
412
} ) ;
404
413
405
414
// @ts -expect-error (schema must not be null)
406
- expect ( ( ) => subscribe ( { schema : null , document } ) ) . to . throw (
415
+ expect ( ( ) => subscribeWithBadArgs ( { schema : null , document } ) ) . to . throw (
407
416
'Expected null to be a GraphQL schema.' ,
408
417
) ;
409
418
410
419
// @ts -expect-error
411
- expect ( ( ) => subscribe ( { document } ) ) . to . throw (
420
+ expect ( ( ) => subscribeWithBadArgs ( { document } ) ) . to . throw (
412
421
'Expected undefined to be a GraphQL schema.' ,
413
422
) ;
414
423
415
424
// @ts -expect-error (document must not be null)
416
- expect ( ( ) => subscribe ( { schema, document : null } ) ) . to . throw (
425
+ expect ( ( ) => subscribeWithBadArgs ( { schema, document : null } ) ) . to . throw (
417
426
'Must provide document.' ,
418
427
) ;
419
428
420
429
// @ts -expect-error
421
- expect ( ( ) => subscribe ( { schema } ) ) . to . throw ( 'Must provide document.' ) ;
430
+ expect ( ( ) => subscribeWithBadArgs ( { schema } ) ) . to . throw (
431
+ 'Must provide document.' ,
432
+ ) ;
422
433
} ) ;
423
434
424
435
it ( 'resolves to an error if schema does not support subscriptions' , async ( ) => {
425
436
const schema = new GraphQLSchema ( { query : DummyQueryType } ) ;
426
437
const document = parse ( 'subscription { unknownField }' ) ;
427
438
428
- const result = subscribe ( { schema, document } ) ;
439
+ const result = subscribeWithBadArgs ( { schema, document } ) ;
429
440
expectJSON ( result ) . toDeepEqual ( {
430
441
errors : [
431
442
{
@@ -449,7 +460,7 @@ describe('Subscription Initialization Phase', () => {
449
460
} ) ;
450
461
const document = parse ( 'subscription { unknownField }' ) ;
451
462
452
- const result = subscribe ( { schema, document } ) ;
463
+ const result = subscribeWithBadArgs ( { schema, document } ) ;
453
464
expectJSON ( result ) . toDeepEqual ( {
454
465
errors : [
455
466
{
@@ -472,7 +483,7 @@ describe('Subscription Initialization Phase', () => {
472
483
} ) ;
473
484
474
485
// @ts -expect-error
475
- expect ( ( ) => subscribe ( { schema, document : { } } ) ) . to . throw ( ) ;
486
+ expect ( ( ) => subscribeWithBadArgs ( { schema, document : { } } ) ) . to . throw ( ) ;
476
487
} ) ;
477
488
478
489
it ( 'throws an error if subscribe does not return an iterator' , async ( ) => {
@@ -557,7 +568,7 @@ describe('Subscription Initialization Phase', () => {
557
568
558
569
// If we receive variables that cannot be coerced correctly, subscribe() will
559
570
// resolve to an ExecutionResult that contains an informative error description.
560
- const result = subscribe ( { schema, document, variableValues } ) ;
571
+ const result = subscribeWithBadArgs ( { schema, document, variableValues } ) ;
561
572
expectJSON ( result ) . toDeepEqual ( {
562
573
errors : [
563
574
{
0 commit comments