Skip to content
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

[new feature]/generate model tag #21

Closed
imiskolee opened this issue Feb 22, 2018 · 5 comments
Closed

[new feature]/generate model tag #21

imiskolee opened this issue Feb 22, 2018 · 5 comments
Labels
enhancement New feature or request thinking

Comments

@imiskolee
Copy link

imiskolee commented Feb 22, 2018

if i has this graphql define

type User{
 id : Int!  #user id
 name:String #user name
login_count:Int! #user login count
}

its will be generated a golang struct

type User struct {
 ID int 
Name *string 
Login_count int 
}

i want generated to

type User struct {
 ID int   `gql:"id,desc:'user id'`
Name *string `gql:"name,desc:'user name'"`
Login_count int `gql:"login_count,desc:'user login count'"`
}

and attach more info to field tag.

we can return desc tag of field when request __schema.

@vektah
Copy link
Collaborator

vektah commented Feb 22, 2018

What's the use case?

All of this data and more is already in the schema object, you can fetch it off the generated executable schema es.Schema().

Perhaps mappings need to go from the go struct back to the schema object?

@pandada8
Copy link

one possible use case is that the generated model may be used directly with mgo or other database lib, without redefine or edit the struct again.

@imiskolee
Copy link
Author

@pandada8 dont direct use graphql layer object for database layer . its really not a good idea. trust me.

@vektah vektah added enhancement New feature or request thinking labels Mar 8, 2018
@vektah
Copy link
Collaborator

vektah commented May 3, 2018

I'm going to close this out until there is a good concrete use case.

I don't think gqlgen should be generating your database models, it should be binding to them.

@vektah vektah closed this as completed May 3, 2018
@fr3fou
Copy link

fr3fou commented Sep 5, 2020

@pandada8 dont direct use graphql layer object for database layer . its really not a good idea. trust me.

sorry for necro, but how should this be handled, without running into

  • having to write a lot of boilerplate
  • "desynchronization" of types (say you add a field, you'd now have to add it in 3 places - domain type, db type, gql type)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request thinking
Projects
None yet
Development

No branches or pull requests

4 participants