ghostdogpr / caliban

Functional GraphQL library for Scala

Home Page:https://ghostdogpr.github.io/caliban/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Enums with spaces in name (editted with @GQLName) breaks caliban client gen

clementgohchangming opened this issue · comments

Hello! Needing some help with spaces in enums and client generation!

Is there a way for us to make a caliban enum return spaces, without having the caliban client gen generating spaces for its name in the client file? (causes client gen to fail)

the annotation @GQLName (or directive? seems like this annotation is a directive under the hood) works in giving spaces to an enum

@GQLName("Flying Cats")
case object FlyingCats extends Cats

the caliban output returns spaces as we like it

"cats": "Flying Cats",

but…

it seems that @GQLName also causes calibanClientGen to add spaces to the enum in the generated client file, and gives this error due to spaces in the enum object name

calibanGenClient http://localhost:9000/graphql web/app/com/catcompany/catiq/core/CatsAPI.scala --packageName com.catcompany.catiq.core --genView true
Generating code for http://localhost:9000/graphql
DanglingParentheses: top-level presets deprecated; use 'preset' subsection
parsed config (v2.7.5): .scalafmt.conf
error: Nil.scala: org.scalafmt.dynamic.exceptions.PositionExceptionImpl: Nil.scala:301: error: ; expected but identifier found
case object Flying Cats extends Cats
                   ^
Caused by: Nil.scala:301: error: ; expected but identifier found
case object Flying Cats extends Cats
                   ^

Is there a way to make the Enum contain spaces, without the generated client file having spaces in the generated case object enum? Any solution that involves having to write a custom Directive or custom code is welcome too!

Something like this in the generated Client File:

case object FlyingCats extends Cats

spaces aren't valid in a GQL name /[_A-Za-z][_0-9A-Za-z]*/ :) will be closing this.