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

Use sql.NullString & Co. declaring them in gqlgen.yml config file #1662

Open
frederikhors opened this issue Oct 15, 2021 · 3 comments
Open
Labels
binder Related to mapping Go to GraphQL types question support please use https://discord.gg/DYEq3EMs4U for support questions

Comments

@frederikhors
Copy link
Collaborator

What happened?

I'm trying to avoid pointers as my structs fields.

But gqlgen generates struct like:

type User struct {
	ID        uint64  `json:"id"`
	Nickname  string  `json:"lastname"`
	Img       *string `json:"img"`
}

with *string as you can see.

What did you expect?

I would like to use something like this in gqlgen.yml config file:

models:
  String:
    model:
      - github.com/99designs/gqlgen/graphql.String
      - github.com/99designs/gqlgen/graphql.NullString
      # or maybe also:
      - database/sql.NullString

So to have this instead:

type User struct {
	ID        uint64         `json:"id"`
	Nickname  string         `json:"lastname"`
	Img       sql.NullString `json:"img"`
}
@frederikhors frederikhors changed the title I would like to use sql.NullString & Co. declaring them in gqlgen.yml config file Use sql.NullString & Co. declaring them in gqlgen.yml config file Oct 16, 2021
@lwc lwc added support please use https://discord.gg/DYEq3EMs4U for support questions question binder Related to mapping Go to GraphQL types labels Oct 18, 2021
@oiime
Copy link

oiime commented Dec 27, 2021

I assume the issue is from https://github.com/99designs/gqlgen/blob/master/plugin/modelgen/models.go:

if isStruct(typ) && (fieldDef.Kind == ast.Object || fieldDef.Kind == ast.InputObject) {
	typ = types.NewPointer(typ)
}

which seems to force it into a pointer, guess it could be solved by writing a plugin that checks the type to decide, but this definitely should be configurable or at least denotes by the type

@JamesArthurHolland
Copy link

Did anyone find a solution to this?

@numberinho
Copy link

Ping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
binder Related to mapping Go to GraphQL types question support please use https://discord.gg/DYEq3EMs4U for support questions
Projects
None yet
Development

No branches or pull requests

5 participants