From aed060ff358b48a315db8696989a0b2e8c2c686f Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Tue, 22 Jun 2021 22:14:41 -0700 Subject: [PATCH] Exposing the set of members of emitted enumerations --- tools/src/main/scala/caliban/tools/ClientWriter.scala | 4 ++++ tools/src/test/scala/caliban/tools/ClientWriterSpec.scala | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/tools/src/main/scala/caliban/tools/ClientWriter.scala b/tools/src/main/scala/caliban/tools/ClientWriter.scala index a811a6373..052865885 100644 --- a/tools/src/main/scala/caliban/tools/ClientWriter.scala +++ b/tools/src/main/scala/caliban/tools/ClientWriter.scala @@ -380,6 +380,10 @@ object ClientWriter { .map(v => s"""case ${typedef.name}.${safeEnumValue(v.enumValue)} => __EnumValue("${v.enumValue}")""") .mkString("\n")} } + + val values: Vector[${enumName}] = Vector(${typedef.enumValuesDefinition + .map(v => safeEnumValue(v.enumValue)) + .mkString(", ")}) } """ } diff --git a/tools/src/test/scala/caliban/tools/ClientWriterSpec.scala b/tools/src/test/scala/caliban/tools/ClientWriterSpec.scala index 4add61daa..f45f6a07f 100644 --- a/tools/src/test/scala/caliban/tools/ClientWriterSpec.scala +++ b/tools/src/test/scala/caliban/tools/ClientWriterSpec.scala @@ -236,6 +236,8 @@ object Client { case Origin.MARS => __EnumValue("MARS") case Origin.BELT => __EnumValue("BELT") } + + val values: Vector[Origin] = Vector(EARTH, MARS, BELT) } } @@ -289,6 +291,8 @@ object Client { case Origin.MARS => __EnumValue("MARS") case Origin.BELT => __EnumValue("BELT") } + + val values: Vector[Origin] = Vector(EARTH, MARS, BELT) } case class Routes(origin: Origin, destinations: List[com.example.Destination] = Nil) @@ -599,6 +603,8 @@ object Client { case Episode.JEDI => __EnumValue("JEDI") case Episode.jedi_1 => __EnumValue("jedi") } + + val values: Vector[Episode] = Vector(NEWHOPE, EMPIRE, JEDI, jedi_1) } }