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

Unpredictable and contradictory naming behavior #1383

Closed
JonasDoe opened this issue Nov 3, 2020 · 1 comment · Fixed by #2683
Closed

Unpredictable and contradictory naming behavior #1383

JonasDoe opened this issue Nov 3, 2020 · 1 comment · Fixed by #2683

Comments

@JonasDoe
Copy link
Contributor

JonasDoe commented Nov 3, 2020

What happened?

I generated a models_gen.go based on this schema:

type EmailSmtpInfo {
  emailBCC: String
}

and got:

type EmailSMTPInfo struct {
	EmailBcc *string `json:"emailBCC"`
}

The casing was not as I expected: Parts of of the type name (the Smtp) became fully uppercase - in opposite to the GraphQL schema -, and parts of the field name (the "CC" in BCC) became lowercase (and does not comply with the Go naming standard). And a field like Tls, again, would become fully uppercase.
Taken together the behavior is a bit surprising (especially regarding the Smtp) and in case of the field name deviating from the Go standard, but my main issue is that the behavior is contradictory (enforcing a uppercase sequence vs preventing it).

(I know that Smtp deviates from the Go standard as well, but I had to decide elsewhere whether I want to enforce uppercase sequences or disallow them, and with the current gqlgen behavior nothing works out.)

What did you expect?

Ideally the generator would honor my typing. If that's not possible, that it would be nice if the casing would be at least consistent (i.e. let Smtp with those lowercase letters and keep lowercase "CC" in Bcc). Since I generate the GraphQL schema itself as well as the whole service utilizing it elsewhere and the generation itself is quite abstract, it's hard to deal with that unpredictable behavior in the result - neither preventing an uppercase sequence nor enforcing it leads to a reliable outcome.

I think if you want to keep features like "automatic abbreviation detection & uppercasing", they should remain optional mappers one can register or define in the yaml.

I tried to enforce at least the predictable naming for fields via directives like @goField(name: "emailBCC"), but even then the result will look like "emailBcc".

Minimal graphql.schema and models to reproduce

Just take this GraphQL schema and generate the model with gqlgen generate.

type EmailSmtpInfo {
  emailBCC: String
}

versions

  • gqlgen version? : v0.13.0
  • go version? : 1.15
  • dep or go modules? No further dependencies in the go.mod
@JonasDoe JonasDoe changed the title Unforeseeable and contradictory naming behavior Unpredictable and contradictory naming behavior Nov 3, 2020
@bertiespell
Copy link

Is there any plan to fix this in future versions? This caused an issue for us and to fix we've had to downgrade (from 0.16.0 back to 0.14.0). 🙏

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

Successfully merging a pull request may close this issue.

2 participants