All Downloads are FREE. Search and download functionalities are using the official Maven repository.

caliban.tools.compiletime.CompileTime.scala Maven / Gradle / Ivy

There is a newer version: 2.9.0
Show newest version
package caliban.tools.compiletime

import caliban._
import caliban.tools.Codegen.GenType
import caliban.tools.compiletime.Config.ClientGenerationSettings
import caliban.tools.{ Codegen, SchemaLoader }
import zio.{ ExitCode, UIO, ZIO }

object CompileTime {

  def generateClient[R](
    args: List[String]
  )(api: GraphQL[R], settings: ClientGenerationSettings): UIO[ExitCode] =
    args match {
      case baseDir :: Nil =>
        Codegen
          .generate(
            SchemaLoader.fromCaliban(api),
            settings.toCalibanCommonSettings.toOptions(
              schemaPath = "",
              toPath = {
                val dir = Utils.toPathDir(baseDir, settings.packageName)

                s"$dir/${settings.clientName}.scala"
              }
            ),
            GenType.Client
          )
          .exitCode
      case _              =>
        ZIO
          .fail(new RuntimeException(s"`CompileTime.generateClient` was called with invalid arguments: $args"))
          .exitCode
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy