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

GraphQL Name Collision in overly aggressive "ToGo" conversion #2321

Closed
dcarbone opened this issue Aug 11, 2022 · 1 comment
Closed

GraphQL Name Collision in overly aggressive "ToGo" conversion #2321

dcarbone opened this issue Aug 11, 2022 · 1 comment

Comments

@dcarbone
Copy link
Contributor

dcarbone commented Aug 11, 2022

What happened?

I have a GraphQL schema with the following Enum:

enum MyEnum {
  Value
  value
  TitleValue
  title_value
}

And so-on. This, unfortunately, is forcibly turned into:

type MyEnum string

const (
  MyEnumValue MyEnum = "Value"
  MyEnumValue MyEnum = "value"
  MyEnumTitleValue MyEnum = "TitleValue"
  MyEnumTitleValue MyEnum = "title_value"
)

The obvious issue here is that we have two consts with the same name, but different values.

What did you expect?

The consts to be defined as

type MyEnum string

const (
  MyEnumValue MyEnum = "Value"
  MyEnumvalue MyEnum = "value"
  MyEnumTitleValue MyEnum = "TitleValue"
  MyEnumtitle_value MyEnum = "title_value"
)

or some derivative thereof. Perhaps with an underscore in between the $enum.Name and .Name to make them more readable.

I am working on a PR on this, but I wanted to open this and get some feedback on possible alternative solutions.

Minimal graphql.schema and models to reproduce

enum MyEnum {
  Value
  value
  TitleValue
  title_value
}

versions

  • gqlgen version: v0.17.13
  • go version: go1.18.5
@dcarbone dcarbone changed the title "ToGo" is unecessarily aggressive "ToGo" is unnecessarily aggressive Aug 11, 2022
dcarbone added a commit to dcarbone/gqlgen that referenced this issue Aug 12, 2022
dcarbone added a commit to dcarbone/gqlgen that referenced this issue Aug 12, 2022
dcarbone added a commit to dcarbone/gqlgen that referenced this issue Aug 12, 2022
@StevenACoffman StevenACoffman changed the title "ToGo" is unnecessarily aggressive Case Insensitive GraphQL Name Collision in "ToGo" Aug 16, 2022
@StevenACoffman StevenACoffman changed the title Case Insensitive GraphQL Name Collision in "ToGo" GraphQL Name Collision in overly aggressive "ToGo" Aug 16, 2022
@StevenACoffman StevenACoffman changed the title GraphQL Name Collision in overly aggressive "ToGo" GraphQL Name Collision in overly aggressive "ToGo" conversion Aug 16, 2022
StevenACoffman pushed a commit that referenced this issue Aug 18, 2022
* Initial pass at #2321

* using ReplaceAllStringLiteral

* fixing wordInfo template test

* bumping linter timeout to 5m

* comment cleanup

* some cleanup, adding "ToGoPrivateModelName" func

* adding "ToGoPrivateModelName" func

* refactoring word walker impl and tests

* hopefully making linter happy
@dcarbone
Copy link
Contributor Author

closed with #2322

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

1 participant