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

Incorrect Encoder Generation with Reserved keywords #55

Closed
BinaryHexer opened this issue Apr 11, 2018 · 2 comments
Closed

Incorrect Encoder Generation with Reserved keywords #55

BinaryHexer opened this issue Apr 11, 2018 · 2 comments

Comments

@BinaryHexer
Copy link

It seems graphqelm will generate incorrect encoders if the record type contains reserved keywords like type.

Generated Code (Incorrect):

{-| Type for the Input input object.
-}
type alias Input =
    { apiVersion : String, type_ : String, payload : String }


{-| Encode a Input into a value that can be used as an argument.
-}
encodeInput : Input -> Value
encodeInput input =
    Encode.maybeObject
        [ ( "apiVersion", Encode.string input.apiVersion |> Just ), ( "type_", Encode.string input.type_ |> Just ), ( "payload", Encode.string input.payload |> Just ) ]

Schema:

input Input {
  apiVersion: String!
  type: String!
  payload: String!
}

type Mutation {
  processInput(input: Input!): JobEntity!
}

In the above example, graphqelm should generate encoder as follows:

{-| Encode a Input into a value that can be used as an argument.
-}
encodeInput : Input -> Value
encodeInput input =
    Encode.maybeObject
        [ ( "apiVersion", Encode.string input.apiVersion |> Just ), ( "type", Encode.string input.type_ |> Just ), ( "payload", Encode.string input.payload |> Just ) ]

Notice the lack of _ in the string type

@dillonkearns
Copy link
Owner

@BinaryHexer thank you so much for reporting the issue! This is now fixed with npm version 3.1.12 👍

@BinaryHexer
Copy link
Author

Thanks for the quick resolution :)

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