gqlgen icon indicating copy to clipboard operation
gqlgen copied to clipboard

False positive for initialism detection "GUID" when generating enum

Open andrejgou opened this issue 3 years ago • 2 comments

What happened?

When generating any enum that includes "GUID", it is always detected as an initialism and thus capitalized in the resulting go const. There is a workaround to just write CamelCase enums, but that conflicts with any style guide that uses SHOUTING_SNAKE_CASE for enums, which is what's used in the graphql.org documentation

Evidently "GUID" is a common initialism, but the word "guide" is fairly common.

With the following graphql schema:

enum Resource {
    GUIDANCE
    TOUR_GUIDE
    GUIDE_FEE
    GUIDELINES
}

the resulting go code is generated:

const (
    ResourceGUIDAnce        Resource = "GUIDANCE"
    ResourceTourGUIDE       Resource = "TOUR_GUIDE"
    ResourceGUIDEFee        Resource = "GUIDE_FEE"
    ResourceGUIDElines      Resource = "GUIDELINES"
)

What did you expect?

generated go code:

const (
    ResourceGuidance        Resource = "GUIDANCE"
    ResourceTourGuide       Resource = "TOUR_GUIDE"
    ResourceGuideFee        Resource = "GUIDE_FEE"
    ResourceGuidelines      Resource = "GUIDELINES"
)

Minimal graphql.schema and models to reproduce

enum Resource {
    GUIDANCE
    TOUR_GUIDE
    GUIDE_FEE
    GUIDELINES
}

I don't believe any models or config are relevant.

versions

  • go run github.com/99designs/gqlgen version? 0.14.0
  • go version? 1.17

andrejgou avatar Apr 28 '22 18:04 andrejgou

Did you try with latest version?

frederikhors avatar Apr 28 '22 19:04 frederikhors

I tried again with 0.17.4 and got the same result.

andrejgou avatar Apr 29 '22 01:04 andrejgou