Skip to content

Commit

Permalink
Generator improvements (ghostdogpr#1137)
Browse files Browse the repository at this point in the history
* add interface generation

* improve generator

* add interface generation

* refactor generators code and test
* delete redundant implicits package

* add interface generation

* refactor generators code and test
* delete redundant implicits package

* add interface generation

* refactor generators code and test
* delete redundant implicits package

* add interface generation

* refactor generators code and test
* delete redundant implicits package

* add interface generation

* fix test

* add interface generation

* fix formatting

* add interface generation

* fix formatting

* add interface generation

* fix formatting

* add interface generation

* merge master branch

* add interface generation

* merge master branch
  • Loading branch information
nikodemin authored and Fluxx committed Jan 13, 2022
1 parent a6cf00a commit 9ef6eee
Show file tree
Hide file tree
Showing 16 changed files with 1,347 additions and 1,389 deletions.
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

0 comments on commit 9ef6eee

Please sign in to comment.