Skip to content

Commit 571b22a

Browse files
Scala: fix deprecated APIs, support generateSealedInterfaces (#1042)
1 parent dd0dbdc commit 571b22a

File tree

22 files changed

+464
-254
lines changed

22 files changed

+464
-254
lines changed

.github/workflows/check-code-style.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ jobs:
1717
- name: Checkout
1818
uses: actions/checkout@v2
1919

20+
# brew install sbt; cd graphql-java-codegen-sbt-plugin; sbt fmt or sbt check
21+
- name: Check Scala Code Style
22+
working-directory: plugins/sbt/graphql-java-codegen-sbt-plugin
23+
run: sbt check
24+
2025
- name: Check Code Style
2126
env:
2227
WORKDIR: ./

docs/codegen-options.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
| `generatedLanguage` | Enum | GeneratedLanguage.JAVA | Choose which language you want to generate, Java,Scala,Kotlin were supported. Note that due to language features, there are slight differences in default values between languages. |
5959
| `generateModelOpenClasses` | Boolean | False | The class type of the generated model. If true, generate normal classes, else generate data classes. It only support in kotlin(```data class```) and scala(```case class```). Maybe we will consider to support Java ```record``` in the future. |
6060
| `initializeNullableTypes` | Boolean | False | Adds a default null value to nullable arguments. Only supported in Kotlin. |
61-
| `generateSealedInterfaces` | Boolean | False | This applies to generated interfaces on unions and interfaces. If true, generate sealed interfaces, else generate normal ones. It is only supported in Kotlin. |
61+
| `generateSealedInterfaces` | Boolean | False | This applies to generated interfaces on unions and interfaces. If true, generate sealed interfaces, else generate normal ones. It is only supported in Kotlin and Scala. |
6262
| `typesAsInterfaces` | Set(String) | Empty | Types that must generated as interfaces should be defined here in format: `TypeName` or `@directive`. E.g.: `User`, `@asInterface`. |
6363
| `useObjectMapperForRequestSerialization` | Set(String) | Empty | Fields that require serialization using `com.fasterxml.jackson.databind.ObjectMapper#writeValueAsString(Object)`. Values should be defined here in the following format: `GraphqlObjectName.fieldName` or `GraphqlTypeName`. If just type is specified, then all fields of this type will be serialized using ObjectMapper. E.g.: `["Person.createdDateTime", ZonedDateTime"]` |
6464
| `supportUnknownFields` | Boolean | False | Specifies whether api classes should support unknown fields during serialization or deserialization. If `true`, classes will include a property of type [`java.util.Map<String,Object>`](https://docs.oracle.com/javase/8/docs/api/index.html?java/util/Map.html) that will store unknown fields. |
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
version = "3.6.1"
2+
runner.dialect = scala213
3+
maxColumn = 120
4+
align.preset = more
5+
lineEndings = preserve
6+
align.stripMargin = false
7+
docstrings.style = AsteriskSpace
8+
docstrings.oneline = keep
9+
continuationIndent.defnSite = 2
10+
danglingParentheses.preset = true
11+
spaces {
12+
inImportCurlyBraces = true
13+
}
14+
indentOperator.exemptScope = aloneArgOrBody
15+
includeCurlyBraceInSelectChains = false
16+
align.openParenDefnSite = false
17+
optIn.annotationNewlines = true
18+
rewrite.rules = [SortImports, RedundantBraces]
19+
rewriteTokens = {
20+
"⇒": "=>"
21+
"→": "->"
22+
"←": "<-"
23+
}

plugins/sbt/graphql-java-codegen-sbt-plugin/.scalariform.conf

Lines changed: 0 additions & 11 deletions
This file was deleted.

plugins/sbt/graphql-java-codegen-sbt-plugin/build.sbt

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ jValidationVersion := "2.0.1.Final"
88

99
// keep version is equals with parent project `graphql-java-codegen`.
1010
// Plugin don't need to care about the scala version, just the SBT version.
11-
lazy val `graphql-codegen-sbt-plugin` = Project(id = "graphql-codegen-sbt-plugin", base = file(".")).
12-
enablePlugins(SbtPlugin, BuildInfoPlugin).
13-
settings(Publishing.publishSettings).
14-
settings(
15-
sbtPlugin := true,
11+
lazy val `graphql-codegen-sbt-plugin` = Project(id = "graphql-codegen-sbt-plugin", base = file("."))
12+
.enablePlugins(SbtPlugin, BuildInfoPlugin)
13+
.settings(Publishing.publishSettings)
14+
.settings(
15+
sbtPlugin := true,
1616
scriptedBufferLog := false,
17+
commands ++= Commands.value,
1718
scriptedLaunchOpts += s"-Dplugin.version=${version.value}",
1819
scalacOptions += "-target:jvm-1.8",
1920
releaseIgnoreUntrackedFiles := true,
@@ -31,12 +32,12 @@ lazy val `graphql-codegen-sbt-plugin` = Project(id = "graphql-codegen-sbt-plugin
3132
pushChanges
3233
),
3334
libraryDependencies ++= Seq(
34-
"io.github.kobylynskyi" % "graphql-java-codegen" % (version in ThisBuild).value,
35-
"org.freemarker" % "freemarker" % "2.3.31",
36-
"com.graphql-java" % "graphql-java" % "16.2",
37-
"com.fasterxml.jackson.core" % "jackson-databind" % "2.12.1",
38-
"com.typesafe" % "config" % "1.4.2"
35+
"io.github.kobylynskyi" % "graphql-java-codegen" % (ThisBuild / version).value,
36+
"org.freemarker" % "freemarker" % "2.3.31",
37+
"com.graphql-java" % "graphql-java" % "16.2",
38+
"com.fasterxml.jackson.core" % "jackson-databind" % "2.12.1",
39+
"com.typesafe" % "config" % "1.4.2"
3940
),
40-
buildInfoKeys := Seq[BuildInfoKey](name, version, sbtVersion, jValidationVersion),
41+
buildInfoKeys := Seq[BuildInfoKey](name, version, sbtVersion, jValidationVersion),
4142
buildInfoPackage := "io.github.dreamylost.graphql.codegen"
42-
)
43+
)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import sbt.Command
2+
3+
/** @author
4+
* 梦境迷离
5+
* @since 2022/1/15
6+
* @version 1.0
7+
*/
8+
object Commands {
9+
10+
val FmtSbtCommand = Command.command("fmt")(state => "scalafmtSbt" :: "scalafmtAll" :: state)
11+
12+
val FmtSbtCheckCommand =
13+
Command.command("check")(state => "scalafmtSbtCheck" :: "scalafmtCheckAll" :: state)
14+
15+
val value = Seq(
16+
FmtSbtCommand,
17+
FmtSbtCheckCommand
18+
)
19+
20+
}

plugins/sbt/graphql-java-codegen-sbt-plugin/project/Publishing.scala

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ import sbt._
22
import sbt.Keys._
33
import xerial.sbt.Sonatype.autoImport.sonatypeProfileName
44

5-
/**
6-
* sbt publish setting
5+
/** sbt publish setting
76
*
8-
* @author 梦境迷离
9-
* @since 2020-07-19
10-
* @version v1.0
7+
* @author
8+
* 梦境迷离
9+
* @since 2020-07-19
10+
* @version v1.0
1111
*/
1212
object Publishing {
1313

14-
//publish by sbt publishSigned
14+
// publish by sbt publishSigned
1515
lazy val publishSettings = Seq(
1616
credentials += Credentials(Path.userHome / ".ivy2" / ".sonatype_credentials"),
1717
publishTo := {
@@ -21,25 +21,27 @@ object Publishing {
2121
else
2222
Some("releases" at nexus + "service/local/staging/deploy/maven2")
2323
},
24-
licenses := Seq("MIT" -> url("https://opensource.org/licenses/MIT")),
25-
publishMavenStyle := true,
24+
licenses := Seq("MIT" -> url("https://opensource.org/licenses/MIT")),
25+
publishMavenStyle := true,
2626
publishArtifact in Test := false,
27-
pomIncludeRepository := { _ => false },
27+
pomIncludeRepository := { _ => false },
2828
developers := List(
2929
Developer(
3030
id = "dreamylost",
3131
name = "梦境迷离",
3232
email = "[email protected]",
33-
url = url("https://dreamylost.cn")
34-
)),
33+
url = url("https://blog.dreamylost.cn")
34+
)
35+
),
3536
sonatypeProfileName := organization.value,
36-
isSnapshot := version.value endsWith "SNAPSHOT",
37-
homepage := Some(url("https://github.com/jxnu-liguobin")),
37+
isSnapshot := version.value endsWith "SNAPSHOT",
38+
homepage := Some(url("https://github.com/jxnu-liguobin")),
3839
scmInfo := Some(
3940
ScmInfo(
40-
//it is fork from https://github.com/kobylynskyi/graphql-java-codegen
41+
// it is fork from https://github.com/kobylynskyi/graphql-java-codegen
4142
url("https://github.com/jxnu-liguobin/graphql-java-codegen"),
4243
"scm:[email protected]:jxnu-liguobin/graphql-java-codegen.git"
43-
))
44+
)
45+
)
4446
)
4547
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.8.3")
2-
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0")
1+
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.0")
2+
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0")
33
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.13")
44
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2")
5-
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.13")
5+
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.13")

plugins/sbt/graphql-java-codegen-sbt-plugin/src/main/scala/io/github/dreamylost/graphql/codegen/Compat.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,24 @@ import sbt.io.{ AllPassFilter, SuffixFilter }
77
import sbt.{ Def, Task }
88
import sbt.Configuration
99

10-
/**
11-
*
12-
* @author 梦境迷离
13-
* @since 2020-07-18
14-
* @version v1.0
10+
/** @author
11+
* 梦境迷离
12+
* @since 2020-07-18
13+
* @version v1.0
1514
*/
1615
trait Compat {
1716
self: GraphQLCodegenPlugin =>
1817

1918
import self.GlobalImport._
2019

21-
val watchSourcesSetting: Def.Setting[Task[Seq[WatchSource]]] = {
20+
val watchSourcesSetting: Def.Setting[Task[Seq[WatchSource]]] =
2221
watchSources += new Source(
23-
(sourceDirectory in graphqlCodegen).value,
22+
(graphqlCodegen / sourceDirectory).value,
2423
new SuffixFilter(".graphql") | new SuffixFilter(".graphqls"),
25-
AllPassFilter)
26-
}
24+
AllPassFilter
25+
)
2726

28-
protected[this] lazy val GraphQLCodegenConfig = Configuration.of("GraphQLCodegen", "graphqlCodegen" + configurationPostfix)
27+
protected[this] lazy val GraphQLCodegenConfig =
28+
Configuration.of("GraphQLCodegen", "graphqlCodegen" + configurationPostfix)
2929

3030
}

0 commit comments

Comments
 (0)