dillonkearns / elm-graphql

Autogenerate type-safe GraphQL queries in Elm.

Home Page:https://package.elm-lang.org/packages/dillonkearns/elm-graphql/latest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Enum with underscore as a leading character, changed after generating elm code.

johnykifle opened this issue · comments

Hi,

I have an enum that looks like this on my schema

enum PictureFormat {
    _2D
    _3D
    IMAX
    _4D_PLUS
} 

The generated elm code

type PictureFormat
    = 2d_
    | 3d_
    | Imax
    | 4dPlus_

Looks like In the generated code has the underscore at the type? Is this intended feature or bug?

Normalization is intended behavior. Elm Custom Type Variants can't begin with an underscore so they need to be normalized. It would be ideal if all valid GraphQL identifiers could map to valid Elm identifiers directly, but since Elm has stricter rules for identifiers they need to be normalized.

There are some tests here in case that's interesting for reference: https://github.com/dillonkearns/elm-graphql/blob/068056540eb566fdf888aa1620605173b7b96511/generator/tests/Generator/NormalizeTests.elm

The 4dPlus_ case is actually something that needs to be normalized but is not yet. It starts with a number, which is not valid in an Elm identifier. That issue is tracked in #88, so I'll close this issue and track the leading number fix there.

Hope that clarifies it! Happy to give more details if you have more questions on that.