sangria icon indicating copy to clipboard operation
sangria copied to clipboard

Fix enum derivation

Open wordrak opened this issue 1 year ago • 1 comments

Fix enum derivation when the enum composed of case objects but they are not within another class

wordrak avatar Oct 09 '24 13:10 wordrak

@wordrak thanks a lot for the PR. To help me reviewing this, could you explain more what the actual issue is?

yanns avatar Oct 09 '24 14:10 yanns

Hi, issue is that the deriveEnumType macro fails when the Enum is a "case object hierarchy" and it is not contained in another object.

e.g.:

  sealed trait Fruit

  case object RedApple extends Fruit
  case object SuperBanana extends Fruit
  case object MegaOrange extends Fruit
  
  object Fruit {
    implicit val enumType = deriveEnumType[Fruit]()
  }

If you revert the changes in the TestCase then you see the problem.

wordrak avatar Oct 28 '24 08:10 wordrak

instead of creating the term derive.SuperBanana that is failing:

[error] /Users/yannsimon/projects/sangria-graphql/sangria/modules/derivation/src/test/scala/sangria/macros/derive/DeriveEnumTypeMacroSpec.scala:55:48: not found: value derive
[error]       val singletonEnum = deriveEnumType[Fruit]()
[error]                                                ^

we now create the term SuperBanana.

yanns avatar Oct 28 '24 09:10 yanns

Thanks a lot!

yanns avatar Oct 28 '24 10:10 yanns