ermadmi78 / kobby

Kobby is a codegen plugin of Kotlin DSL Client by GraphQL schema. The generated DSL supports execution of complex GraphQL queries, mutation and subscriptions in Kotlin with syntax similar to native GraphQL syntax.
Apache License 2.0
83 stars 4 forks source link

Validation error when deserializing nested GraphQL inputs #13

Closed ermadmi78 closed 3 years ago

ermadmi78 commented 3 years ago

Let define nested GraphQL inputs:

enum ShapeType {
    POINT,
    LINE,
    POLYGON
}

input PointInput {
    x: Float!
    y: Float!
}

input ShapeInput {
    type: ShapeType!
    points: [PointInput!]!
    holes: [[PointInput!]!]
}

The ShapeInput contains nested PointInput. For such an inputs Kobby generates DTO classes:

public enum class ShapeType {
  POINT,
  LINE,
  POLYGON,
}

@JsonTypeName(value = "PointInput")
@JsonTypeInfo(
  use = JsonTypeInfo.Id.NAME,
  include = JsonTypeInfo.As.PROPERTY,
  property = "__typename",
  defaultImpl = PointInput::class
)
@JsonInclude(value = JsonInclude.Include.NON_ABSENT)
public data class PointInput(
  public val x: Double,
  public val y: Double
)

@JsonTypeName(value = "ShapeInput")
@JsonTypeInfo(
  use = JsonTypeInfo.Id.NAME,
  include = JsonTypeInfo.As.PROPERTY,
  property = "__typename",
  defaultImpl = ShapeInput::class
)
@JsonInclude(value = JsonInclude.Include.NON_ABSENT)
public data class ShapeInput(
  public val type: ShapeType,
  public val points: List<PointInput>,
  public val holes: List<List<PointInput>>? = null
)

When I try to send the ShapeInput with nested PointInput to GraphQL server I receive an validation error:

The variables input contains a field name '__typename' that is not defined for input object type 'PointInput'

To avoid such validation errors Kobby must not generate the JsonTypeName and the JsonTypeInfo annotations for input GraphQL types. For other GraphQL types, the behavior should remain the same.

ermadmi78 commented 3 years ago

Fixed. Ready for release.

ermadmi78 commented 3 years ago

Fixed in release 1.2.0