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

Change type of errorType field in Error DTO class from enum to String #33

Closed ermadmi78 closed 1 year ago

ermadmi78 commented 1 year ago

To deserialize the error in the GraphQL response, Kobby generates a DTO class that looks like this:

public data class CinemaError(
  public val message: String,
  @JsonInclude(value = JsonInclude.Include.NON_EMPTY)
  public val locations: List<CinemaErrorSourceLocation>? = null,
  @JsonInclude(value = JsonInclude.Include.NON_ABSENT)
  public val errorType: CinemaErrorType? = null,
  @JsonInclude(value = JsonInclude.Include.NON_EMPTY)
  public val path: List<Any>? = null,
  @JsonInclude(value = JsonInclude.Include.NON_EMPTY)
  public val extensions: Map<String, Any?>? = null,
) 

The errorType field is enum:

public enum class CinemaErrorType {
  InvalidSyntax,
  ValidationError,
  DataFetchingException,
  OperationNotSupported,
  ExecutionAborted,
}

This enum limits the possible error type to 5 values. But there are no standards for possible error types in GraphQL responses, which sometimes results in deserialization errors. For example, in this case, the error type is UnauthorizedException.

I think we should stop using enums for error types and return the error type as a String.

ermadmi78 commented 1 year ago

Fixed in release 2.1.1