@@ -38,7 +38,6 @@ import type {
38
38
GraphQLTypeResolver ,
39
39
} from '../type/definition.js' ;
40
40
import {
41
- getNamedType ,
42
41
isAbstractType ,
43
42
isLeafType ,
44
43
isListType ,
@@ -631,26 +630,19 @@ function executeFieldsSerially(
631
630
( results , [ responseName , fieldGroup ] ) => {
632
631
const fieldPath = exeContext . addPath ( path , responseName , parentType . name ) ;
633
632
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 ) ) {
643
634
return results ;
644
635
}
645
636
const result = executeField (
646
637
exeContext ,
647
638
parentType ,
648
- fieldDef ,
649
- returnType ,
650
639
sourceValue ,
651
640
fieldGroup ,
652
641
fieldPath ,
653
642
) ;
643
+ if ( result === undefined ) {
644
+ return results ;
645
+ }
654
646
if ( isPromise ( result ) ) {
655
647
return result . then ( ( resolvedResult ) => {
656
648
results [ responseName ] = resolvedResult ;
@@ -666,25 +658,11 @@ function executeFieldsSerially(
666
658
667
659
function shouldExecute (
668
660
fieldGroup : FieldGroup ,
669
- returnType : GraphQLOutputType ,
670
661
deferDepth ?: number | undefined ,
671
662
) : 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
+ ) ;
688
666
}
689
667
690
668
/**
@@ -706,22 +684,10 @@ function executeFields(
706
684
for ( const [ responseName , fieldGroup ] of groupedFieldSet ) {
707
685
const fieldPath = exeContext . addPath ( path , responseName , parentType . name ) ;
708
686
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 ) ) {
720
688
const result = executeField (
721
689
exeContext ,
722
690
parentType ,
723
- fieldDef ,
724
- returnType ,
725
691
sourceValue ,
726
692
fieldGroup ,
727
693
fieldPath ,
@@ -769,15 +735,19 @@ function toNodes(fieldGroup: FieldGroup): ReadonlyArray<FieldNode> {
769
735
function executeField (
770
736
exeContext : ExecutionContext ,
771
737
parentType : GraphQLObjectType ,
772
- fieldDef : GraphQLField < unknown , unknown > ,
773
- returnType : GraphQLOutputType ,
774
738
source : unknown ,
775
739
fieldGroup : FieldGroup ,
776
740
path : Path ,
777
741
asyncPayloadRecord ?: AsyncPayloadRecord ,
778
742
) : PromiseOrValue < unknown > {
779
743
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
+ }
780
749
750
+ const returnType = fieldDef . type ;
781
751
const resolveFn = fieldDef . resolve ?? exeContext . fieldResolver ;
782
752
783
753
const info = buildResolveInfo (
@@ -786,6 +756,7 @@ function executeField(
786
756
fieldGroup ,
787
757
parentType ,
788
758
path ,
759
+ asyncPayloadRecord ,
789
760
) ;
790
761
791
762
// Get the resolve function, regardless of if its result is normal or abrupt (error).
@@ -865,12 +836,14 @@ export function buildResolveInfo(
865
836
fieldGroup : FieldGroup ,
866
837
parentType : GraphQLObjectType ,
867
838
path : Path ,
839
+ asyncPayloadRecord ?: AsyncPayloadRecord | undefined ,
868
840
) : GraphQLResolveInfo {
869
841
// The resolve function's optional fourth argument is a collection of
870
842
// information about the current execution state.
871
843
return {
872
844
fieldName : fieldDef . name ,
873
- fieldNodes : toNodes ( fieldGroup ) ,
845
+ fieldGroup,
846
+ deferDepth : asyncPayloadRecord ?. deferDepth ,
874
847
returnType : fieldDef . type ,
875
848
parentType,
876
849
path,
@@ -1222,7 +1195,6 @@ function completeListValue(
1222
1195
// This is specified as a simple map, however we're optimizing the path
1223
1196
// where the list contains no Promises by avoiding creating another Promise.
1224
1197
let containsPromise = false ;
1225
- const deferDepth = asyncPayloadRecord ?. deferDepth ;
1226
1198
let previousAsyncPayloadRecord = asyncPayloadRecord ;
1227
1199
const completedResults : Array < unknown > = [ ] ;
1228
1200
let index = 0 ;
@@ -1244,7 +1216,6 @@ function completeListValue(
1244
1216
fieldGroup ,
1245
1217
info ,
1246
1218
itemType ,
1247
- deferDepth ,
1248
1219
previousAsyncPayloadRecord ,
1249
1220
) ;
1250
1221
index ++ ;
@@ -1923,11 +1894,10 @@ function executeStreamField(
1923
1894
fieldGroup : FieldGroup ,
1924
1895
info : GraphQLResolveInfo ,
1925
1896
itemType : GraphQLOutputType ,
1926
- deferDepth : number | undefined ,
1927
1897
parentContext ?: AsyncPayloadRecord ,
1928
1898
) : AsyncPayloadRecord {
1929
1899
const asyncPayloadRecord = new StreamRecord ( {
1930
- deferDepth,
1900
+ deferDepth : parentContext ?. deferDepth ,
1931
1901
path : itemPath ,
1932
1902
parentContext,
1933
1903
exeContext,
0 commit comments