-
Notifications
You must be signed in to change notification settings - Fork 490
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
implement sql.Scanner and driver.Value for graphql.ID type #40
Conversation
@nicksrandall sorry, I don't use sql backend but could see it may useful for others. |
What about this: Have your own |
Having to always cast to graphql.ID is what I'm trying to avoid. Currently my structs use strings for ID prop and I have to cast to graphql.ID in resolvers. I use strings for the DB. This change would allow me to not have to worry about casting in all the right places. This also allows me to use the same struct for resolvers as input type because input type requires ID type (to be idiomatic). I imagine that anybody using this lib with a SQL backend would find this helpful. Am I wrong? What are your concerns with adding this? |
Would everyone who uses this library and a SQL backend want this exact implementation, or would their needs differ slightly? |
Anybody using the sql package in the standard lib would need this exact implementation. EDIT: I can't say that definitively. My guess is that this would cover a large majority of people using the standard sql package. |
I still think that it is beneficial to have a clear separation between resolver API and underlying data structures. The resolvers are a view/projection on the underlying data. To me it feels like your change would mix this up a bit. On the other hand I see that there currently is a strict 1-to-1 coupling between the GraphQL type One option would be to accept any named There might be some good solution around custom resolvers. You could use any type as the result type for |
What I have ended up doing is adding my own custom scalar type |
@nicksrandall Please take a look at 2b513d7 and #3 (comment). This should be a proper solution here. |
I like it! Thanks @neelance. I close this PR |
@nicksrandall @neelance First of all, thank you for your work!! Sorry to dig in the past, but could you please explain me how I can apply the proposed solution to my case? I'm using SQL with IDs defined as integers. As a new gopher, It's not clear where and how I should implement this.. |
I ran into the same situation regarding the scalar Time. I solved it at the moment by editing
This offers me the possibility to use this same struct for GraphQL and GORM:
However, I'd really like to apply your proposition (using |
This makes
graphql.ID
type implement sql.Scanner and driver.Valuer. This simplifies the data structures that I'm using so that they can implement the types that graphql likes but can also be marshaled into the DB.