caliban icon indicating copy to clipboard operation
caliban copied to clipboard

Client: autogenerate view classes from query

Open benwaffle opened this issue 4 years ago • 5 comments

It would be useful to write the graphql query as a string and generate the view classes

val query = gql"""
{
  character("Amos Burton") {
    name
    nicknames
    origin
  }
}
"""

// autogenerate this
case class CharacterView(name: String, nickname: List[String], origin: Origin)
case class QueryResponse(character: List[CharacterView])

benwaffle avatar Aug 31 '20 16:08 benwaffle

Do you have any plan to implement the feature? Anyway, is there any workaround how to generate view classes?

viclovsky avatar Oct 29 '20 13:10 viclovsky

I think that would require some macros, I have no knowledge about that (and not really willing to learn now since Scala 3 will make it obsolete :D), but open to contributions.

ghostdogpr avatar Oct 29 '20 13:10 ghostdogpr

@viclovsky @benwaffle I am working on something like this for a project (using macros). Right now I am able to generate case classes for simple queries but I hope to cover more complex selections in the near future. If you have any particular need/suggestion please feel free to share.

askmrsinh avatar Dec 01 '20 00:12 askmrsinh

FYI it is now possible to generate view classes when running the code gen (it's slightly different from your example though: it generates view classes with all fields (not based on any query).

ghostdogpr avatar Mar 27 '21 02:03 ghostdogpr