Skip to content

Commit 424d61d

Browse files
committed
u- return alias field
1 parent f02a1c9 commit 424d61d

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

definition.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ type FieldResolveFn func(p ResolveParams) (interface{}, error)
589589

590590
type ResolveInfo struct {
591591
FieldName string
592+
FieldNameAlias string
592593
FieldASTs []*ast.Field
593594
Path *ResponsePath
594595
ReturnType Output

executor.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,11 @@ func resolveField(eCtx *executionContext, parentType *Object, source interface{}
610610
fieldName = fieldAST.Name.Value
611611
}
612612

613+
fieldNameAlias := ""
614+
if fieldAST.Alias != nil {
615+
fieldNameAlias = fieldAST.Alias.Value
616+
}
617+
613618
fieldDef := getFieldDef(eCtx.Schema, parentType, fieldName)
614619
if fieldDef == nil {
615620
resultState.hasNoFieldDefs = true
@@ -628,6 +633,7 @@ func resolveField(eCtx *executionContext, parentType *Object, source interface{}
628633

629634
info := ResolveInfo{
630635
FieldName: fieldName,
636+
FieldNameAlias: fieldNameAlias,
631637
FieldASTs: fieldASTs,
632638
Path: path,
633639
ReturnType: returnType,
@@ -982,6 +988,13 @@ func DefaultResolveFn(p ResolveParams) (interface{}, error) {
982988
// try p.Source as a map[string]interface
983989
if sourceMap, ok := p.Source.(map[string]interface{}); ok {
984990
property := sourceMap[p.Info.FieldName]
991+
if p.Info.FieldNameAlias != "" {
992+
propertyAlias, pok := sourceMap[p.Info.FieldNameAlias]
993+
if pok {
994+
property = propertyAlias
995+
}
996+
}
997+
985998
val := reflect.ValueOf(property)
986999
if val.IsValid() && val.Type().Kind() == reflect.Func {
9871000
// try type casting the func to the most basic func signature

0 commit comments

Comments
 (0)