From 540fcbf3290a784228baa9045fec8f8e19cfdb01 Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Wed, 23 Jun 2021 18:43:30 -0700 Subject: [PATCH] Exposing the set of members of emitted enumerations (#934) --- 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 b2af2d9be..f19774617 100644 --- a/tools/src/main/scala/caliban/tools/ClientWriter.scala +++ b/tools/src/main/scala/caliban/tools/ClientWriter.scala @@ -382,6 +382,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 f275e3e65..8641ce0f4 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) } }