@@ -11,8 +11,6 @@ import type { DocumentNode } from '../language/ast';
1111import type { GraphQLSchema } from '../type/schema' ;
1212import type { GraphQLFieldResolver } from '../type/definition' ;
1313
14- import { getOperationRootType } from '../utilities/getOperationRootType' ;
15-
1614import type {
1715 ExecutionArgs ,
1816 ExecutionResult ,
@@ -194,16 +192,24 @@ async function executeSubscription(
194192) : Promise < unknown > {
195193 const { schema, fragments, operation, variableValues, rootValue } =
196194 exeContext ;
197- const type = getOperationRootType ( schema , operation ) ;
198- const fields = collectFields (
195+
196+ const rootType = schema . getSubscriptionType ( ) ;
197+ if ( rootType == null ) {
198+ throw new GraphQLError (
199+ 'Schema is not configured to execute subscription operation.' ,
200+ operation ,
201+ ) ;
202+ }
203+
204+ const rootFields = collectFields (
199205 schema ,
200206 fragments ,
201207 variableValues ,
202- type ,
208+ rootType ,
203209 operation . selectionSet ,
204210 ) ;
205- const [ responseName , fieldNodes ] = [ ...fields . entries ( ) ] [ 0 ] ;
206- const fieldDef = getFieldDef ( schema , type , fieldNodes [ 0 ] ) ;
211+ const [ responseName , fieldNodes ] = [ ...rootFields . entries ( ) ] [ 0 ] ;
212+ const fieldDef = getFieldDef ( schema , rootType , fieldNodes [ 0 ] ) ;
207213
208214 if ( ! fieldDef ) {
209215 const fieldName = fieldNodes [ 0 ] . name . value ;
@@ -213,8 +219,14 @@ async function executeSubscription(
213219 ) ;
214220 }
215221
216- const path = addPath ( undefined , responseName , type . name ) ;
217- const info = buildResolveInfo ( exeContext , fieldDef , fieldNodes , type , path ) ;
222+ const path = addPath ( undefined , responseName , rootType . name ) ;
223+ const info = buildResolveInfo (
224+ exeContext ,
225+ fieldDef ,
226+ fieldNodes ,
227+ rootType ,
228+ path ,
229+ ) ;
218230
219231 try {
220232 // Implements the "ResolveFieldEventStream" algorithm from GraphQL specification.
0 commit comments