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

Encode function for enums is missing #634

Open
ad-si opened this issue Aug 14, 2023 · 1 comment
Open

Encode function for enums is missing #634

ad-si opened this issue Aug 14, 2023 · 1 comment

Comments

@ad-si
Copy link

ad-si commented Aug 14, 2023

I have following GraphQL Enum:

enum Order {
  ASC
  DESC
}

It generates an src/Api/Enum/Order.elm file with following type:

type Order
    = Asc
    | Desc

However, the generated src/Api/InputObject.elm file references a function encodeOrder which isn't defined anywhere.

I was able to fix it by adding it manually:

encodeOrder : Order -> Value
encodeOrder =
    Encode.enum <|
        \val ->
            case val of
                Asc ->
                    "ASC"

                Desc ->
                    "DESC"

Is this a bug and it should be generated automatically, or am I missing something?

@dillonkearns
Copy link
Owner

It looks like the generated code uses the enum's toString functions within the InputObject module. Here's an example of what is generated for the Star Wars API example:

[ ( "language", Encode.enum Swapi.Enum.Language.toString |> Encode.optional input____.language ), ( "name", Encode.string input____.name |> Just ), ( "options", encodeGreetingOptions |> Encode.optional input____.options ) ]

So it appears that the basic case of encoding an enum within an InputObject is working as expected.

If you think there might be a bug, I would be interested to see a minimum reproduction of the relevant schema. There are some instructions for making a minimum reproduction here: https://github.com/dillonkearns/elm-graphql/blob/master/reproducing-issues/README.md

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

2 participants