Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape function name properly in interface client generation #1225

Merged
merged 1 commit into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tools/src/main/scala/caliban/tools/ClientWriter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
(
Expand Down
14 changes: 7 additions & 7 deletions tools/src/test/scala/caliban/tools/ClientWriterSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ object Client {
name: String!
}
type Sort {
order: Order
object: Order
}
""".stripMargin

Expand All @@ -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`)))
}

}
Expand Down