-
Notifications
You must be signed in to change notification settings - Fork 843
How should pointers to standard types be handled when no Resolve
is defined?
#101
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
Comments
I think it'd be best to make it a declaration on the type of some sort, like refValue := reflect.ValueOf(field)
fieldValue := refValue.Elem()
return coerceInt(fieldValue) (Granted, tons of a additional testing) If this seems like a good approach I'll get started implementing it. |
The current API already has |
The current behavior for non-nil pointers is to serialize their memory On Sunday, January 24, 2016, Augusto Roman [email protected] wrote:
|
Sorry -- I understand that it's not working correctly right now, however I don't think adding a "pointer" type to the API is the right solution. Rather, the standard Scalar types should automatically dereference non-nil pointers without you having to specify anything in the API, IMO. |
This is what I was looking for. I figure the same thing but wanted to seek On Sunday, January 24, 2016, Augusto Roman [email protected] wrote:
|
@augustoroman @bbuck I think that would probably be a good enhancement to the library. But we might want to consider if this needed to handled by the library or let the user of the library to implement a custom Scalar Type. There are already an API to do that. Discussions/ PRs would be greatly welcomed 👍🏻 |
I still stick with my suggested implementation concept of having it be a wrapper type like List for values. Otherwise we end up with a significant amount of pollution in the already large I'll spin up a PR as soon as I can for it. |
After completing a PR to fix this issue, I think allowing custom scalar types would be quite simple if we grouped the logic for evaluation into the type itself. Right now the logic is built into type Executer interface {
Execute(*ExecutionContext, Type, []*ast.Field, ResolveInfo, interface{}) interface{}
} Then users can easily supply their own Scalar type by just defining it and using like any other Type value. Of course, you'd want to group all the methods into a I can look into working up a PR to make types more dynamic. |
Updating this issue with comments that I added to PR #114 Currently I have reservations about introducing a new type to graphql-go that goes beyond the current published spec. GraphQL is still very much in its early infancy and things does get change pretty quickly (we barely have enough time to achieve parity with graphql-js at the moment lol). I think currently #101 fits the use case for a user-defined Scalar type. This means that the user can create a new Scalar type named Pointer through existing API graphql.NewScalar(), similar how built-in types like Float, String and Int are defined in the library. If anyone need a complete example of how to implement a custom scalar type using graphql.NewScalar(), I can spend some time writing that a gist for it. Thanks again! Edit: I'm not sure if you have already tried the graphql.NewScalar() approach. If you have already, maybe you could share issues and obstacles that you had faced when trying to implement the Pointer type. ... |
@sogko My initial concern with the Because Go is different, and has this unique aspect to the language (and a way to handle it) I think it makes perfect sense to a Pointer type to exist within the Go port of GraphQL. Just like I'd expect any JavaScript oddities to be handled by the JS implementation but not be present in the Go implementation. Yea, it's off spec too, but again. The spec is language agnostic and we're ultimately weighing whether we support a native language feature in our native language implementation and I think in that case it makes sense. |
Hi @bbuck Thanks for bringing up those points for discussion, I do think that your concerns are valid 😃 I agree with you that since this library is written on Go, it should take advantage of the language and its capabilities fully 👍🏻 I failed to elaborate previously why I had reservations about including Pointers type as part of the built-in library. Consider this: 1: Let's talk in JSON, everybody =) (Side note: The 52-bit truncation for Int type is a lax implementation; strictly, Int should be of 32-bit value. This implementation was ported from 2: Clients ideally should not worry about platform-specifics of the GraphQL server As such, we have to be mindful about introducing Go-specific features into the built-in Type System. Keeping those points above in mind, it's natural to standby the position that platform specific features/quirks should be handled in user-defined custom types. 3: Pointer type
In my personal humble opinion: It is too early to fork off the published GraphQL spec at this time, since every thing is still new and things are bound to change. I can just imagine the chaos in maintenance lol 🔥 😅 I hope that I managed to add useful and valuable points into this discussion, I would encourage discussion from others as well! Cheers guys! 🍻😃 Edit: I hope that I don't come across as a specs zealot lol, I'm trying to contribute to this project by expressing my opinions regarding what I believe is best for it in the long run, given the information at hand at this moment, as every one of you do. Healthy discussion about issues like this is good, Useful references: Re: how to handle Int bigger than 32-bits:
Re: The ability to write custom Scalar types, for e.g.
|
I know that if I had a struct like this:
Then I could simply define a type with a field called
"username"
and a type ofgraphql.String
and then another field"age"
with a type ofgraphql.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:Do you think the standard Scalar types should support pointers as well? Or should there be a wrapper type like
Type: graphql.NewPointer(...)
?The text was updated successfully, but these errors were encountered: