ghostdogpr / caliban

Functional GraphQL library for Scala

Home Page:https://ghostdogpr.github.io/caliban/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Scala 3 different schema derivation enum names

guymers opened this issue · comments

The following produces a different schema depending on the Scala version:

@GQLName("PrefixOperator")
sealed trait Operator
object Operator {
  @GQLName("PrefixOperatorGreaterThan")
  case object GreaterThan extends Operator {
    implicit val schema: Schema[Any, GreaterThan.type] = Schema.gen
  }

  @GQLName("PrefixOperatorLessThan")
  case object LessThan extends Operator {
    implicit val schema: Schema[Any, LessThan.type] = Schema.gen
  }

  implicit val schema: Schema[Any, Operator] = Schema.gen
}

case class Queries(
  op: Operator,
)
object Queries {
  implicit val schema: Schema[Any, Queries] = Schema.gen
}

val schema = {
  val queries = Queries(op = Operator.LessThan)
  caliban.graphQL(RootResolver(queries))
}

Scala 2:

schema {
  query: Queries
}

enum PrefixOperator {
  PrefixOperatorGreaterThan
  PrefixOperatorLessThan
}

type Queries {
  op: PrefixOperator!
}

Scala 3:

schema {
  query: Queries
}

enum PrefixOperator {
  GreaterThan
  LessThan
}

type Queries {
  op: PrefixOperator!
}

Thanks for reporting these issues - our Scala 3 derivation uses Scala 3's built-in generic derivation instead of Magnolia. While this gives us more flexibility, it also means that we have a few inconsistencies / small bugs in some edge cases

No worries, thanks for the fixing them so quickly.