File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -964,6 +964,22 @@ func DefaultResolveFn(p ResolveParams) (interface{}, error) {
964
964
return property , nil
965
965
}
966
966
967
+ // Try accessing as map via reflection
968
+ if r := reflect .ValueOf (p .Source ); r .Kind () == reflect .Map && r .Type ().Key ().Kind () == reflect .String {
969
+ val := r .MapIndex (reflect .ValueOf (p .Info .FieldName ))
970
+ if val .IsValid () {
971
+ property := val .Interface ()
972
+ if val .Type ().Kind () == reflect .Func {
973
+ // try type casting the func to the most basic func signature
974
+ // for more complex signatures, user have to define ResolveFn
975
+ if propertyFn , ok := property .(func () interface {}); ok {
976
+ return propertyFn (), nil
977
+ }
978
+ }
979
+ return property , nil
980
+ }
981
+ }
982
+
967
983
// last resort, return nil
968
984
return nil , nil
969
985
}
You can’t perform that action at this time.
0 commit comments