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

Generator improvements #1137

Merged
merged 13 commits into from
Nov 18, 2021
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package caliban.codegen

import caliban.tools.CalibanCommonSettings
import caliban.tools.Codegen.GenType

import java.io.File
import java.net.URL
Expand All @@ -19,6 +20,7 @@ final case class CalibanFileSettings(file: File, settings: CalibanCommonSettings
def splitFiles(value: Boolean): CalibanFileSettings = this.copy(settings = this.settings.splitFiles(value))
def enableFmt(value: Boolean): CalibanFileSettings = this.copy(settings = this.settings.enableFmt(value))
def extensibleEnums(value: Boolean): CalibanFileSettings = this.copy(settings = this.settings.extensibleEnums(value))
def genType(genType: GenType): CalibanFileSettings = this.copy(settings = this.settings.genType(genType))
}

final case class CalibanUrlSettings(url: URL, settings: CalibanCommonSettings) extends CalibanSettings {
Expand All @@ -34,4 +36,5 @@ final case class CalibanUrlSettings(url: URL, settings: CalibanCommonSettings) e
def splitFiles(value: Boolean): CalibanUrlSettings = this.copy(settings = this.settings.splitFiles(value))
def enableFmt(value: Boolean): CalibanUrlSettings = this.copy(settings = this.settings.enableFmt(value))
def extensibleEnums(value: Boolean): CalibanUrlSettings = this.copy(settings = this.settings.extensibleEnums(value))
def genType(genType: GenType): CalibanUrlSettings = this.copy(settings = this.settings.genType(genType))
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package caliban.codegen

import _root_.caliban.tools.Codegen.GenType
import _root_.caliban.tools._
import sbt._
import sjsonnew.IsoLList.Aux
Expand Down Expand Up @@ -30,7 +29,7 @@ object CalibanSourceGenerator {
implicit val analysisIso: Aux[TrackedSettings, Seq[String] :*: LNil] =
LList.iso[TrackedSettings, Seq[String] :*: LNil](
{ case TrackedSettings(arguments) => ("args", arguments) :*: LNil },
{ case ((_, args) :*: LNil) => TrackedSettings(args) }
{ case (_, args) :*: LNil => TrackedSettings(args) }
)
}

Expand Down Expand Up @@ -78,7 +77,7 @@ object CalibanSourceGenerator {
generatedSource <- ZIO.succeed(transformFile(sourceRoot, sourceManaged, settings)(graphql))
_ <- Task(sbt.IO.createDirectory(generatedSource.toPath.getParent.toFile)).asSomeError
opts <- ZIO.fromOption(Some(settings.toOptions(graphql.toString, generatedSource.toString)))
files <- Codegen.generate(opts, GenType.Client).asSomeError
files <- Codegen.generate(opts, settings.genType).asSomeError
} yield files

def generateUrlSource(
Expand All @@ -92,7 +91,7 @@ object CalibanSourceGenerator {
)
_ <- Task(sbt.IO.createDirectory(generatedSource.toPath.getParent.toFile)).asSomeError
opts <- ZIO.fromOption(Some(settings.toOptions(graphql.toString, generatedSource.toString)))
files <- Codegen.generate(opts, GenType.Client).asSomeError
files <- Codegen.generate(opts, settings.genType).asSomeError
} yield files

Runtime.default
Expand Down
12 changes: 9 additions & 3 deletions tools/src/main/scala/caliban/tools/CalibanCommonSettings.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package caliban.tools

import caliban.tools.Codegen.GenType

final case class CalibanCommonSettings(
clientName: Option[String],
scalafmtPath: Option[String],
Expand All @@ -10,7 +12,8 @@ final case class CalibanCommonSettings(
imports: Seq[String],
splitFiles: Option[Boolean],
enableFmt: Option[Boolean],
extensibleEnums: Option[Boolean]
extensibleEnums: Option[Boolean],
genType: GenType
) {

private[caliban] def toOptions(schemaPath: String, toPath: String): Options =
Expand Down Expand Up @@ -42,7 +45,8 @@ final case class CalibanCommonSettings(
imports = this.imports ++ r.imports,
splitFiles = r.splitFiles.orElse(this.splitFiles),
enableFmt = r.enableFmt.orElse(this.enableFmt),
extensibleEnums = r.extensibleEnums.orElse(this.extensibleEnums)
extensibleEnums = r.extensibleEnums.orElse(this.extensibleEnums),
genType = r.genType
)

def clientName(value: String): CalibanCommonSettings = this.copy(clientName = Some(value))
Expand All @@ -56,6 +60,7 @@ final case class CalibanCommonSettings(
def splitFiles(value: Boolean): CalibanCommonSettings = this.copy(splitFiles = Some(value))
def enableFmt(value: Boolean): CalibanCommonSettings = this.copy(enableFmt = Some(value))
def extensibleEnums(value: Boolean): CalibanCommonSettings = this.copy(extensibleEnums = Some(value))
def genType(genType: GenType): CalibanCommonSettings = this.copy(genType = genType)
}

object CalibanCommonSettings {
Expand All @@ -70,6 +75,7 @@ object CalibanCommonSettings {
imports = Seq.empty,
splitFiles = None,
enableFmt = None,
extensibleEnums = None
extensibleEnums = None,
GenType.Client
)
}
Loading