graphql-go / graphql-go/graphql
How should pointers to standard types be handled when no `Resolve` is defined?
- Dominant language
- Go
- Stars
- 10.1k
- Forks
- 845
- PR merge metrics
- No merged PRs in 30d
Description
I know that if I had a struct like this:
``` go
type User struct {
Username *string `json:"username"`
Age *int `json:"age"`
}
```
Then I could simply define a type with a field called `"username"` and a type of `graphql.String` and then another field `"age"` with a type of `graphql.Int` and the fields would "auto-resolve". However, I've been defining GraphQL types for AWS API return values and AWS uses a lot of pointers in their structs. For example their IDs/Names are an 'aws.String' which is basically `*string` so the pointer address is returned in the GraphQL response. Obviously this is not what is desired, but it's odd to have this all over the place:
``` go
// ...
Resolve: func(params graphql.ResolveParams) (interface{}, error) {
source := params.Source.(*User)
return *source.Username, nil
}
// ...
Resolve: func(params graphql.ResolveParams) (interface{}, error) {
source := params.Source.(*User)
return *source.Age, nil
}
```
Do you think the standard Scalar types should support pointers as well? Or should there be a wrapper type like `Type: graphql.NewPointer(...)`?
Contributor guide
Assessment
This issue has not been assessed yet.