-
Notifications
You must be signed in to change notification settings - Fork 845
fix: DefaultResolveFn
should handle with map[K]V
for K
that has string
as the underlying type
#697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
… `string` as the underlying type The current implementation returns the following errors for maps with a custom type for keys: ``` reflect.Value.MapIndex: value of type string is not assignable to type .* ```
@chris-ramon could you please merge that? it fixes a bug |
Hi @bkrukowski - thanks for sending a PR. I gave a quick look, the change is not needed, since the end result of val := r.MapIndex(reflect.ValueOf(p.Info.FieldName).Convert(r.Type().Key())) Could you provide an example of the following error you shared above ? - That is related to the PR ? reflect.Value.MapIndex: value of type string is not assignable to type .* |
… `string` as the underlying type The current implementation returns the following errors for maps with a custom type for keys: ``` reflect.Value.MapIndex: value of type string is not assignable to type .* ```
… `string` as the underlying type The current implementation returns the following errors for maps with a custom type for keys: ``` reflect.Value.MapIndex: value of type string is not assignable to type .* ```
@chris-ramon please take a look, I removed that code without removing the newly added test, and it fails: ![]() The following code creates a new value of the reflect.ValueOf(p.Info.FieldName) It causes an issue for maps that have keys of a custom type, and the underlying type is type (
CustomMap map[string]interface{}
CustomKey string
CustomMap2 map[CustomKey]interface{}
)
// ...
scenarios := []struct {
query string
data interface{}
expected interface{}
}{
{ // it works
query: query,
data: CustomMap{
"a": "1",
"b": "2",
},
expected: map[string]interface{}{
"data": map[string]interface{}{
"a": "1",
},
},
},
{ // it does not work without the suggested patch
query: query,
data: CustomMap2{
"a": "1",
"b": "2",
},
expected: map[string]interface{}{
"data": map[string]interface{}{
"a": "1",
},
},
},
} |
@bkrukowski as explained before in the comment: #697 (comment) - The change is not needed, going ahead and closing the PR. |
@chris-ramon kindly please take a look TL;DRThe given code panics here, and I think you missed that point. Full story
it's incorrect
No, it isn't. Without the suggested fix that code panics because we pass a wrong argument to package main
import (
"github.com/graphql-go/graphql"
)
type MyKey string
type MyMap map[MyKey]any
func main() {
myMap := MyMap{"key": "value"}
graphql.DefaultResolveFn(graphql.ResolveParams{Source: myMap})
} Output:
https://go.dev/play/p/2LiyVcmhqUq Since that library recovers all the panics, it returns the following error eventually:
|
The current implementation returns the following errors for maps with a custom type for keys: