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

Initialisms with digits in the middle of them aren't recognized #3170

Open
konatacarneiro opened this issue Jul 4, 2024 · 1 comment
Open

Comments

@konatacarneiro
Copy link

konatacarneiro commented Jul 4, 2024

What happened?

In an application, there's a certain query type called "p2p". During generation, the function name for the query resolver gets converted to pascal case and becomes "P2p" which is undesirable. So I declared the initialism "P2P" in gqlgen.yml to fix this issue, but the initialism seems to be ignored and the expected resolver field name is still "P2p".

What did you expect?

I expected the "P2P" initialism to be applied to the "p2p" query type upon capitalization, yielding the resolver name "P2P", not "P2p".

Minimal graphql.schema and models to reproduce

type P2PModel {
  id: ID!
  text: String!
}

type Query {
  p2p(id: ID!): P2PModel!
}

input NewP2P {
  text: String!
}

type Mutation {
  create_p2p(input: NewP2P!): P2PModel!
}

In gqlgen.yml, include the following:

go_initialisms:
  initialisms:
    - "P2P"

versions

  • go run github.com/99designs/gqlgen version: v0.17.49
  • go version go1.22.1 linux/amd64
@konatacarneiro
Copy link
Author

Upon further investigation, the issue seems to lie in this code segment inside codegen/templates/templates.go::wordWalker():

		case unicode.IsLower(runes[i]) && !unicode.IsLower(runes[i+1]):
			// lower->non-lower
			eow = true

The function unicode.IsLower returns true whenever the input rune is a lowercase letter, and returns false for anything else - including digits and special characters. As such, the "2" in "p2p" is treated as the start of a new word, splitting it into "p" and "2p", neither of which match the initialism "P2P".

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