@@ -179,25 +179,54 @@ export function execute(args: ExecutionArgs): PromiseOrValue<ExecutionResult> {
179179 return { errors : exeContext } ;
180180 }
181181
182- return executeImpl ( exeContext ) ;
182+ return executeOperation ( exeContext ) ;
183183}
184184
185- function executeImpl (
185+ /**
186+ * Implements the "Executing operations" section of the spec.
187+ *
188+ * Returns a Promise that will eventually resolve to the data described by
189+ * The "Response" section of the GraphQL specification.
190+ *
191+ * If errors are encountered while executing a GraphQL field, only that
192+ * field and its descendants will be omitted, and sibling fields will still
193+ * be executed. An execution which encounters errors will still result in a
194+ * resolved Promise.
195+ *
196+ * Errors from sub-fields of a NonNull type may propagate to the top level,
197+ * at which point we still log the error and null the parent field, which
198+ * in this case is the entire response.
199+ */
200+ function executeOperation (
186201 exeContext : ExecutionContext ,
187202) : PromiseOrValue < ExecutionResult > {
188- // Return a Promise that will eventually resolve to the data described by
189- // The "Response" section of the GraphQL specification.
190- //
191- // If errors are encountered while executing a GraphQL field, only that
192- // field and its descendants will be omitted, and sibling fields will still
193- // be executed. An execution which encounters errors will still result in a
194- // resolved Promise.
195- //
196- // Errors from sub-fields of a NonNull type may propagate to the top level,
197- // at which point we still log the error and null the parent field, which
198- // in this case is the entire response.
199203 try {
200- const result = executeOperation ( exeContext ) ;
204+ const { operation, schema, fragments, variableValues, rootValue } =
205+ exeContext ;
206+ const rootType = schema . getRootType ( operation . operation ) ;
207+ if ( rootType == null ) {
208+ throw new GraphQLError (
209+ `Schema is not configured to execute ${ operation . operation } operation.` ,
210+ { nodes : operation } ,
211+ ) ;
212+ }
213+
214+ const groupedFieldSet = collectFields (
215+ schema ,
216+ fragments ,
217+ variableValues ,
218+ rootType ,
219+ operation . selectionSet ,
220+ ) ;
221+
222+ const result = executeRootGroupedFieldSet (
223+ exeContext ,
224+ operation . operation ,
225+ rootType ,
226+ rootValue ,
227+ groupedFieldSet ,
228+ ) ;
229+
201230 if ( isPromise ( result ) ) {
202231 return result . then (
203232 ( data ) => buildResponse ( data , exeContext . errors ) ,
@@ -342,46 +371,28 @@ function buildPerEventExecutionContext(
342371 } ;
343372}
344373
345- /**
346- * Implements the "Executing operations" section of the spec.
347- */
348- function executeOperation (
374+ function executeRootGroupedFieldSet (
349375 exeContext : ExecutionContext ,
376+ operation : OperationTypeNode ,
377+ rootType : GraphQLObjectType ,
378+ rootValue : unknown ,
379+ groupedFieldSet : GroupedFieldSet ,
350380) : PromiseOrValue < ObjMap < unknown > > {
351- const { operation, schema, fragments, variableValues, rootValue } =
352- exeContext ;
353- const rootType = schema . getRootType ( operation . operation ) ;
354- if ( rootType == null ) {
355- throw new GraphQLError (
356- `Schema is not configured to execute ${ operation . operation } operation.` ,
357- { nodes : operation } ,
358- ) ;
359- }
360-
361- const groupedFieldSet = collectFields (
362- schema ,
363- fragments ,
364- variableValues ,
365- rootType ,
366- operation . selectionSet ,
367- ) ;
368- const path = undefined ;
369-
370- switch ( operation . operation ) {
381+ switch ( operation ) {
371382 case OperationTypeNode . QUERY :
372383 return executeFields (
373384 exeContext ,
374385 rootType ,
375386 rootValue ,
376- path ,
387+ undefined ,
377388 groupedFieldSet ,
378389 ) ;
379390 case OperationTypeNode . MUTATION :
380391 return executeFieldsSerially (
381392 exeContext ,
382393 rootType ,
383394 rootValue ,
384- path ,
395+ undefined ,
385396 groupedFieldSet ,
386397 ) ;
387398 case OperationTypeNode . SUBSCRIPTION :
@@ -391,7 +402,7 @@ function executeOperation(
391402 exeContext ,
392403 rootType ,
393404 rootValue ,
394- path ,
405+ undefined ,
395406 groupedFieldSet ,
396407 ) ;
397408 }
@@ -1269,7 +1280,7 @@ function mapSourceToResponse(
12691280 // "ExecuteSubscriptionEvent" algorithm, as it is nearly identical to the
12701281 // "ExecuteQuery" algorithm, for which `execute` is also used.
12711282 return mapAsyncIterable ( resultOrStream , ( payload : unknown ) =>
1272- executeImpl ( buildPerEventExecutionContext ( exeContext , payload ) ) ,
1283+ executeOperation ( buildPerEventExecutionContext ( exeContext , payload ) ) ,
12731284 ) ;
12741285}
12751286
0 commit comments