File tree Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Original file line number Diff line number Diff line change @@ -996,16 +996,18 @@ func DefaultResolveFn(p ResolveParams) (interface{}, error) {
996
996
// Try accessing as map via reflection
997
997
if r := reflect .ValueOf (p .Source ); r .Kind () == reflect .Map && r .Type ().Key ().Kind () == reflect .String {
998
998
fieldNameValue := reflect .ValueOf (p .Info .FieldName )
999
- mapKeyType := r .Type ().Key ()
1000
999
// The map key type might be a string type alias and its underlying type is string,
1001
1000
// but it will be panic if we try to use it as a string value in `MapIndex`.
1002
1001
// So we need to convert the value of the field name to the map key type before
1003
1002
// using it as a map key.
1004
1003
//
1005
1004
// Related issue: https://github.com/graphql-go/graphql/issues/700
1006
- if ! fieldNameValue .CanConvert (mapKeyType ) {
1005
+ //
1006
+ // We cannot use `CanConvert` here since we need to be compatible with Go before 1.17.
1007
+ if fieldNameValue .Kind () != reflect .String {
1007
1008
return nil , nil
1008
1009
}
1010
+ mapKeyType := r .Type ().Key ()
1009
1011
fieldNameValue = fieldNameValue .Convert (mapKeyType )
1010
1012
1011
1013
val := r .MapIndex (fieldNameValue )
You can’t perform that action at this time.
0 commit comments