@@ -38,7 +38,6 @@ import type {
3838 GraphQLTypeResolver ,
3939} from '../type/definition.js' ;
4040import {
41- getNamedType ,
4241 isAbstractType ,
4342 isLeafType ,
4443 isListType ,
@@ -631,26 +630,19 @@ function executeFieldsSerially(
631630 ( results , [ responseName , fieldGroup ] ) => {
632631 const fieldPath = exeContext . addPath ( path , responseName , parentType . name ) ;
633632
634- const fieldName = fieldGroup [ 0 ] . fieldNode . name . value ;
635- const fieldDef = exeContext . schema . getField ( parentType , fieldName ) ;
636- if ( ! fieldDef ) {
637- return results ;
638- }
639-
640- const returnType = fieldDef . type ;
641-
642- if ( ! shouldExecute ( fieldGroup , returnType ) ) {
633+ if ( ! shouldExecute ( fieldGroup ) ) {
643634 return results ;
644635 }
645636 const result = executeField (
646637 exeContext ,
647638 parentType ,
648- fieldDef ,
649- returnType ,
650639 sourceValue ,
651640 fieldGroup ,
652641 fieldPath ,
653642 ) ;
643+ if ( result === undefined ) {
644+ return results ;
645+ }
654646 if ( isPromise ( result ) ) {
655647 return result . then ( ( resolvedResult ) => {
656648 results [ responseName ] = resolvedResult ;
@@ -666,25 +658,11 @@ function executeFieldsSerially(
666658
667659function shouldExecute (
668660 fieldGroup : FieldGroup ,
669- returnType : GraphQLOutputType ,
670661 deferDepth ?: number | undefined ,
671662) : boolean {
672- if ( deferDepth === undefined || ! isLeafType ( getNamedType ( returnType ) ) ) {
673- return fieldGroup . some (
674- ( { deferDepth : fieldDeferDepth } ) => fieldDeferDepth === deferDepth ,
675- ) ;
676- }
677-
678- let hasDepth = false ;
679- for ( const { deferDepth : fieldDeferDepth } of fieldGroup ) {
680- if ( fieldDeferDepth === undefined ) {
681- return false ;
682- }
683- if ( fieldDeferDepth === deferDepth ) {
684- hasDepth = true ;
685- }
686- }
687- return hasDepth ;
663+ return fieldGroup . some (
664+ ( { deferDepth : fieldDeferDepth } ) => fieldDeferDepth === deferDepth ,
665+ ) ;
688666}
689667
690668/**
@@ -706,22 +684,10 @@ function executeFields(
706684 for ( const [ responseName , fieldGroup ] of groupedFieldSet ) {
707685 const fieldPath = exeContext . addPath ( path , responseName , parentType . name ) ;
708686
709- const fieldName = fieldGroup [ 0 ] . fieldNode . name . value ;
710- const fieldDef = exeContext . schema . getField ( parentType , fieldName ) ;
711- if ( ! fieldDef ) {
712- continue ;
713- }
714-
715- const returnType = fieldDef . type ;
716-
717- if (
718- shouldExecute ( fieldGroup , returnType , asyncPayloadRecord ?. deferDepth )
719- ) {
687+ if ( shouldExecute ( fieldGroup , asyncPayloadRecord ?. deferDepth ) ) {
720688 const result = executeField (
721689 exeContext ,
722690 parentType ,
723- fieldDef ,
724- returnType ,
725691 sourceValue ,
726692 fieldGroup ,
727693 fieldPath ,
@@ -769,15 +735,19 @@ function toNodes(fieldGroup: FieldGroup): ReadonlyArray<FieldNode> {
769735function executeField (
770736 exeContext : ExecutionContext ,
771737 parentType : GraphQLObjectType ,
772- fieldDef : GraphQLField < unknown , unknown > ,
773- returnType : GraphQLOutputType ,
774738 source : unknown ,
775739 fieldGroup : FieldGroup ,
776740 path : Path ,
777741 asyncPayloadRecord ?: AsyncPayloadRecord ,
778742) : PromiseOrValue < unknown > {
779743 const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
744+ const fieldName = fieldGroup [ 0 ] . fieldNode . name . value ;
745+ const fieldDef = exeContext . schema . getField ( parentType , fieldName ) ;
746+ if ( ! fieldDef ) {
747+ return ;
748+ }
780749
750+ const returnType = fieldDef . type ;
781751 const resolveFn = fieldDef . resolve ?? exeContext . fieldResolver ;
782752
783753 const info = buildResolveInfo (
@@ -786,6 +756,7 @@ function executeField(
786756 fieldGroup ,
787757 parentType ,
788758 path ,
759+ asyncPayloadRecord ,
789760 ) ;
790761
791762 // Get the resolve function, regardless of if its result is normal or abrupt (error).
@@ -865,12 +836,14 @@ export function buildResolveInfo(
865836 fieldGroup : FieldGroup ,
866837 parentType : GraphQLObjectType ,
867838 path : Path ,
839+ asyncPayloadRecord ?: AsyncPayloadRecord | undefined ,
868840) : GraphQLResolveInfo {
869841 // The resolve function's optional fourth argument is a collection of
870842 // information about the current execution state.
871843 return {
872844 fieldName : fieldDef . name ,
873- fieldNodes : toNodes ( fieldGroup ) ,
845+ fieldGroup,
846+ deferDepth : asyncPayloadRecord ?. deferDepth ,
874847 returnType : fieldDef . type ,
875848 parentType,
876849 path,
@@ -1222,7 +1195,6 @@ function completeListValue(
12221195 // This is specified as a simple map, however we're optimizing the path
12231196 // where the list contains no Promises by avoiding creating another Promise.
12241197 let containsPromise = false ;
1225- const deferDepth = asyncPayloadRecord ?. deferDepth ;
12261198 let previousAsyncPayloadRecord = asyncPayloadRecord ;
12271199 const completedResults : Array < unknown > = [ ] ;
12281200 let index = 0 ;
@@ -1244,7 +1216,6 @@ function completeListValue(
12441216 fieldGroup ,
12451217 info ,
12461218 itemType ,
1247- deferDepth ,
12481219 previousAsyncPayloadRecord ,
12491220 ) ;
12501221 index ++ ;
@@ -1923,11 +1894,10 @@ function executeStreamField(
19231894 fieldGroup : FieldGroup ,
19241895 info : GraphQLResolveInfo ,
19251896 itemType : GraphQLOutputType ,
1926- deferDepth : number | undefined ,
19271897 parentContext ?: AsyncPayloadRecord ,
19281898) : AsyncPayloadRecord {
19291899 const asyncPayloadRecord = new StreamRecord ( {
1930- deferDepth,
1900+ deferDepth : parentContext ?. deferDepth ,
19311901 path : itemPath ,
19321902 parentContext,
19331903 exeContext,
0 commit comments