graphql-kotlin icon indicating copy to clipboard operation
graphql-kotlin copied to clipboard

Generated code for input with non-standard naming fails

Open hameno opened this issue 3 years ago • 1 comments

Library Version 5.5.0

Describe the bug Considering the following schema:

input Filter {
    AND: [Filter!]
    OR: [Filter!]

    id: StringFilter
    name: StringFilter
}

The maven plugin generates the following class for Jackson:

@Generated
public data class Filter(
  public val AND: List<Filter >? = null,
  public val OR: List<Filter >? = null,
  public val id: StringFilter? = null,
  public val name: StringFilter? = null
)

This however will fail to deserialize on the server side, as the request will not send "AND" or "OR" as the name of the field in the JSON. You need to use @JsonProperty for this situation. Is there any way to force this?

To Reproduce see above

Expected behavior Serialized json looks correct

hameno avatar Jul 21 '22 13:07 hameno

Hello 👋 This is indeed an issue with Jackson (kotlinx-serialization does not have this issue) that it does not honor the original field names and instead uses getters to derive the name based on JavaBean conventions. Unsure if this will be addressed within this lib as there are number of issues related to this within jackson-databind - options would be to always annotate the fields with @JsonProperty (which seems like it would redundant for vast majority of cases) OR try to re-implement jackson name logic to determine whether to apply extra annotation (which might be error prone).

dariuszkuc avatar Jul 24 '22 04:07 dariuszkuc

I tried switching to kotlinx but now I'm getting a KotlinFrontEndException: Front-end Internal error: Failed to analyze declaration Variables for the generated Query class.

hameno avatar Oct 06 '22 07:10 hameno