@@ -278,7 +278,7 @@ func executeFields(p ExecuteFieldsParams) *Result {
278
278
p .Fields = map [string ][]* ast.Field {}
279
279
}
280
280
281
- finalResults := map [string ]interface {}{}
281
+ finalResults := make ( map [string ]interface {}, len ( p . Fields ))
282
282
for responseName , fieldASTs := range p .Fields {
283
283
resolved , state := resolveField (p .ExecutionContext , p .ParentType , p .Source , fieldASTs )
284
284
if state .hasNoFieldDefs {
@@ -741,16 +741,16 @@ func completeObjectValue(eCtx *ExecutionContext, returnType *Object, fieldASTs [
741
741
continue
742
742
}
743
743
selectionSet := fieldAST .SelectionSet
744
- if selectionSet != nil {
745
- innerParams := CollectFieldsParams {
746
- ExeContext : eCtx ,
747
- RuntimeType : returnType ,
748
- SelectionSet : selectionSet ,
749
- Fields : subFieldASTs ,
750
- VisitedFragmentNames : visitedFragmentNames ,
751
- }
752
- subFieldASTs = collectFields (innerParams )
744
+ if selectionSet == nil {
745
+ continue
753
746
}
747
+ subFieldASTs = collectFields (CollectFieldsParams {
748
+ ExeContext : eCtx ,
749
+ RuntimeType : returnType ,
750
+ SelectionSet : selectionSet ,
751
+ Fields : subFieldASTs ,
752
+ VisitedFragmentNames : visitedFragmentNames ,
753
+ })
754
754
}
755
755
executeFieldsParams := ExecuteFieldsParams {
756
756
ExecutionContext : eCtx ,
@@ -790,7 +790,7 @@ func completeListValue(eCtx *ExecutionContext, returnType *List, fieldASTs []*as
790
790
}
791
791
792
792
itemType := returnType .OfType
793
- completedResults := []interface {}{}
793
+ completedResults := make ( []interface {}, 0 , resultVal . Len ())
794
794
for i := 0 ; i < resultVal .Len (); i ++ {
795
795
val := resultVal .Index (i ).Interface ()
796
796
completedItem := completeValueCatchingError (eCtx , itemType , fieldASTs , info , val )
@@ -834,29 +834,18 @@ func DefaultResolveFn(p ResolveParams) (interface{}, error) {
834
834
return nil , nil
835
835
}
836
836
if sourceVal .Type ().Kind () == reflect .Struct {
837
+ // try matching the field name first
838
+ if v := sourceVal .FieldByName (p .Info .FieldName ); v .IsValid () {
839
+ return v .Interface (), nil
840
+ }
841
+ var tag reflect.StructTag
837
842
for i := 0 ; i < sourceVal .NumField (); i ++ {
838
- valueField := sourceVal .Field (i )
839
- typeField := sourceVal .Type ().Field (i )
840
- // try matching the field name first
841
- if typeField .Name == p .Info .FieldName {
842
- return valueField .Interface (), nil
843
- }
844
- tag := typeField .Tag
843
+ tag = sourceVal .Type ().Field (i ).Tag
845
844
checkTag := func (tagName string ) bool {
846
- t := tag .Get (tagName )
847
- tOptions := strings .Split (t , "," )
848
- if len (tOptions ) == 0 {
849
- return false
850
- }
851
- if tOptions [0 ] != p .Info .FieldName {
852
- return false
853
- }
854
- return true
845
+ return strings .SplitN (tag .Get (tagName ), "," , 1 )[0 ] == p .Info .FieldName
855
846
}
856
847
if checkTag ("json" ) || checkTag ("graphql" ) {
857
- return valueField .Interface (), nil
858
- } else {
859
- continue
848
+ return sourceVal .Field (i ).Interface (), nil
860
849
}
861
850
}
862
851
return nil , nil
0 commit comments