@@ -14,7 +14,7 @@ import { GraphQLList, GraphQLObjectType } from '../../type/definition';
1414import { GraphQLBoolean , GraphQLInt , GraphQLString } from '../../type/scalars' ;
1515import { GraphQLSchema } from '../../type/schema' ;
1616
17- import type { ExecutionResult } from '../execute' ;
17+ import type { ExecutionArgs , ExecutionResult } from '../execute' ;
1818import { createSourceEventStream , subscribe } from '../execute' ;
1919
2020import { SimplePubSub } from './simplePubSub' ;
@@ -195,6 +195,15 @@ function subscribeWithBadFn(
195195 ) ;
196196}
197197
198+ function subscribeWithBadArgs (
199+ args : ExecutionArgs ,
200+ ) : PromiseOrValue < ExecutionResult | AsyncIterable < unknown > > {
201+ return expectEqualPromisesOrValues (
202+ subscribe ( args ) ,
203+ createSourceEventStream ( args ) ,
204+ ) ;
205+ }
206+
198207/* eslint-disable @typescript-eslint/require-await */
199208// Check all error cases when initializing the subscription.
200209describe ( 'Subscription Initialization Phase' , ( ) => {
@@ -403,29 +412,31 @@ describe('Subscription Initialization Phase', () => {
403412 } ) ;
404413
405414 // @ts -expect-error (schema must not be null)
406- expect ( ( ) => subscribe ( { schema : null , document } ) ) . to . throw (
415+ expect ( ( ) => subscribeWithBadArgs ( { schema : null , document } ) ) . to . throw (
407416 'Expected null to be a GraphQL schema.' ,
408417 ) ;
409418
410419 // @ts -expect-error
411- expect ( ( ) => subscribe ( { document } ) ) . to . throw (
420+ expect ( ( ) => subscribeWithBadArgs ( { document } ) ) . to . throw (
412421 'Expected undefined to be a GraphQL schema.' ,
413422 ) ;
414423
415424 // @ts -expect-error (document must not be null)
416- expect ( ( ) => subscribe ( { schema, document : null } ) ) . to . throw (
425+ expect ( ( ) => subscribeWithBadArgs ( { schema, document : null } ) ) . to . throw (
417426 'Must provide document.' ,
418427 ) ;
419428
420429 // @ts -expect-error
421- expect ( ( ) => subscribe ( { schema } ) ) . to . throw ( 'Must provide document.' ) ;
430+ expect ( ( ) => subscribeWithBadArgs ( { schema } ) ) . to . throw (
431+ 'Must provide document.' ,
432+ ) ;
422433 } ) ;
423434
424435 it ( 'resolves to an error if schema does not support subscriptions' , async ( ) => {
425436 const schema = new GraphQLSchema ( { query : DummyQueryType } ) ;
426437 const document = parse ( 'subscription { unknownField }' ) ;
427438
428- const result = subscribe ( { schema, document } ) ;
439+ const result = subscribeWithBadArgs ( { schema, document } ) ;
429440 expectJSON ( result ) . toDeepEqual ( {
430441 errors : [
431442 {
@@ -449,7 +460,7 @@ describe('Subscription Initialization Phase', () => {
449460 } ) ;
450461 const document = parse ( 'subscription { unknownField }' ) ;
451462
452- const result = subscribe ( { schema, document } ) ;
463+ const result = subscribeWithBadArgs ( { schema, document } ) ;
453464 expectJSON ( result ) . toDeepEqual ( {
454465 errors : [
455466 {
@@ -472,7 +483,7 @@ describe('Subscription Initialization Phase', () => {
472483 } ) ;
473484
474485 // @ts -expect-error
475- expect ( ( ) => subscribe ( { schema, document : { } } ) ) . to . throw ( ) ;
486+ expect ( ( ) => subscribeWithBadArgs ( { schema, document : { } } ) ) . to . throw ( ) ;
476487 } ) ;
477488
478489 it ( 'throws an error if subscribe does not return an iterator' , async ( ) => {
@@ -557,7 +568,7 @@ describe('Subscription Initialization Phase', () => {
557568
558569 // If we receive variables that cannot be coerced correctly, subscribe() will
559570 // resolve to an ExecutionResult that contains an informative error description.
560- const result = subscribe ( { schema, document, variableValues } ) ;
571+ const result = subscribeWithBadArgs ( { schema, document, variableValues } ) ;
561572 expectJSON ( result ) . toDeepEqual ( {
562573 errors : [
563574 {
0 commit comments