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

Optional values should create zero-values in generated code, not pointers. #2568

Closed
ShawnMilo opened this issue Feb 24, 2023 · 1 comment
Closed

Comments

@ShawnMilo
Copy link

What happened?

I added this to my schema:

type Query {
  clients(uid: String, filter: ClientFilter): [Client!]!
}

This code was generated:

func (r *queryResolver) Clients(ctx context.Context, uid *string, filter *model.ClientFilter) ([]model.Client, error) {

This code uses pointers, requiring a lot of boilerplate nil checks and dereferencing.

What did you expect?

func (r *queryResolver) Clients(ctx context.Context, uid string, filter model.ClientFilter) ([]model.Client, error) {

This code would allow a simple if uid == "".

Minimal graphql.schema and models to reproduce

Provided above.

versions

  • gqlgen v0.17.24
  • go version go1.19.4 linux/amd64

I want the arguments to remain optional in the GQL queries, and I do not want pointers, ever.

I went through github.com/99designs/gqlgen/codegen/config/config.go and didn't find any additional settings to avoid pointers. I have all the available ones disabled. Am I just missing something or is this not possible?

@StevenACoffman
Copy link
Collaborator

Hi. For nullable fields, there needs to be a way to indicate null vs an empty string. Please see
#1587

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants