elm-graphql
elm-graphql copied to clipboard
Enums with numbers at the beginning generate invalid code
I have the following graphql enum:
enum Timeframe {
_1MONTH
_2MONTHS
_3MONTHS
_6MONTHS
_1YEAR
_2YEARS
_3YEARS
_5YEARS
_10YEARS
INDEFINITE
}
which elm-graphql 1.0.7 turns into the following elm code:
type IdeaTimeframe
= 1month_
| 2months_
| 3months_
| 6months_
| 1year_
| 2years_
| 3years_
| 5years_
| 10years_
| Indefinite
Unfortunately, Elm doesn't support numbers at the beginning of enum variants, so it doesn't compile.
I'm not sure what the best fix is. If Elm supported it, I would put an underscore at the beginning of the type variants, but that's a no go too.
This is relatively straightforward to fix once we decide on a way to normalize it.
Here are some ideas:
-
N__1month
-
Scalar__1month
-
Number__1month
-
NUMBER__1month
I'm open to other ideas, too. Unfortunately I think it's a case where there's no ideal solution, it'll probably end up looking a little bit ugly. 🤷♂️
Let me know what you think and I'll publish a fix! Thanks for reporting the problem.
@dillonkearns. You're probably right about there not being an ideal solution. Of the options described above I'd probably prefer the first one (N_1month
).
I actually ran into a related problem with lowercase SQL enums, that elm-graphql turned into uppercase values, but that meant that the decoder and encoder didn't work. I'll write up a proper issue at some point.
@Munksgaard thanks for the feedback! N_1month
seems okay to me, too.
Yes, if you give me a schema that can reproduce the problem you encountered that would be super helpful!
A little late to the party here, but I'm having issues with a schema.gql
like
type Query {
_0: String!
}
Thanks again for the brilliant library! :rocket:
When generating elm-graphql types using Wordpress (through wp-graphql) as source, I came across this particular custom type:
type MediaItemSizeEnum
= Large
| Medium
| MediumLarge
| PostThumbnail
| Thumbnail
| 1536x1536_
| 2048x2048_
It follows a similar issue as the first one described above but I'm leaving it here as reference.
And I'm also in favor of N_{type}
🙂