diff --git a/tools/src/main/scala/caliban/tools/ClientWriter.scala b/tools/src/main/scala/caliban/tools/ClientWriter.scala index 89fe4e0cf..cb3a1ef8f 100644 --- a/tools/src/main/scala/caliban/tools/ClientWriter.scala +++ b/tools/src/main/scala/caliban/tools/ClientWriter.scala @@ -206,9 +206,9 @@ object ClientWriter { if (commonInterface) { ( s"[$typeLetter]", - s"(${field.name}: SelectionBuilder[${safeTypeName(getTypeName(field.ofType))}, $typeLetter])", + s"(${safeName(field.name)}: SelectionBuilder[${safeTypeName(getTypeName(field.ofType))}, $typeLetter])", writeType(field.ofType).replace(fieldType, typeLetter), - writeTypeBuilder(field.ofType, s"Obj(${field.name})") + writeTypeBuilder(field.ofType, s"Obj(${safeName(field.name)})") ) } else if (optionalInterface) { ( diff --git a/tools/src/test/scala/caliban/tools/ClientWriterSpec.scala b/tools/src/test/scala/caliban/tools/ClientWriterSpec.scala index 13224f231..d760a4c75 100644 --- a/tools/src/test/scala/caliban/tools/ClientWriterSpec.scala +++ b/tools/src/test/scala/caliban/tools/ClientWriterSpec.scala @@ -854,7 +854,7 @@ object Client { name: String! } type Sort { - order: Order + object: Order } """.stripMargin @@ -877,18 +877,18 @@ object Client { type Sort object Sort { - def order[A](onAscending: SelectionBuilder[Ascending, A]): SelectionBuilder[Sort, Option[A]] = - _root_.caliban.client.SelectionBuilder.Field("order", OptionOf(ChoiceOf(Map("Ascending" -> Obj(onAscending))))) - def orderOption[A]( + def `object`[A](onAscending: SelectionBuilder[Ascending, A]): SelectionBuilder[Sort, Option[A]] = + _root_.caliban.client.SelectionBuilder.Field("object", OptionOf(ChoiceOf(Map("Ascending" -> Obj(onAscending))))) + def objectOption[A]( onAscending: Option[SelectionBuilder[Ascending, A]] = None ): SelectionBuilder[Sort, Option[Option[A]]] = _root_.caliban.client.SelectionBuilder.Field( - "order", + "object", OptionOf( ChoiceOf(Map("Ascending" -> onAscending.fold[FieldBuilder[Option[A]]](NullField)(a => OptionOf(Obj(a))))) ) ) - def orderInterface[A](order: SelectionBuilder[Order, A]): SelectionBuilder[Sort, Option[A]] = - _root_.caliban.client.SelectionBuilder.Field("order", OptionOf(Obj(order))) + def objectInterface[A](`object`: SelectionBuilder[Order, A]): SelectionBuilder[Sort, Option[A]] = + _root_.caliban.client.SelectionBuilder.Field("object", OptionOf(Obj(`object`))) } }