未验证 提交 a9ea3b82 编写于 作者: 梦境迷离's avatar 梦境迷离 提交者: GitHub

Update sbt-plugin for release 3.0.0 (#279)

* add use case with proxy

* add comment

* add Support code

* update README

* add scope on conf key

* add release plugin

* add release plugin

* Setting version to 2.4.2

* Setting version to 2.4.3-SNAPSHOT

* add release plugin (not release)

* upgrade sbt version, update example Deprecated api

* refactor sbt plugin

* refactor sbt plugin

*  Changes for upcoming release 3.0.0 (#276)
上级 e2f1f3b5
......@@ -13,7 +13,7 @@ object Dependencies {
object Versions {
lazy val scala212 = "2.12.12"
lazy val scala211 = "2.11.12"
val codegen = "2.4.1"
val codegen = "3.0.0-SNAPSHOT"
}
import Versions._
......
......@@ -4,6 +4,7 @@ import java.util
import com.kobylynskyi.graphql.codegen.model.{ ApiNamePrefixStrategy, ApiRootInterfaceStrategy }
import sbt._
import com.kobylynskyi.graphql.codegen.model.ApiInterfaceStrategy
/**
*
......@@ -42,7 +43,7 @@ trait GraphQLCodegenKeys {
val typeResolverSuffix = settingKey[String]("typeResolverSuffix")
val customAnnotationsMapping = settingKey[util.Map[String, String]]("customAnnotationsMapping")
val customAnnotationsMapping = settingKey[util.Map[String, util.List[String]]]("customAnnotationsMapping")
val generateEqualsAndHashCode = settingKey[Boolean]("Specifies whether generated model classes should have equals and hashCode methods defined.")
......@@ -97,7 +98,11 @@ trait GraphQLCodegenKeys {
val apiReturnListType = settingKey[Option[String]]("apiReturnListType")
val directiveAnnotationsMapping = settingKey[util.HashMap[String, String]]("directiveAnnotationsMapping")
val directiveAnnotationsMapping = settingKey[util.Map[String, util.List[String]]]("directiveAnnotationsMapping")
val apiInterfaceStrategy = settingKey[ApiInterfaceStrategy]("apiInterfaceStrategy")
val useOptionalForNullableReturnTypes = settingKey[Boolean]("useOptionalForNullableReturnTypes")
//for version
val javaxValidationApiVersion = settingKey[Option[String]]("javax-validation-api version")
......
......@@ -29,7 +29,7 @@ class GraphQLCodegenPlugin(configuration: Configuration, private[codegen] val co
//override this by graphqlJavaCodegenVersion and javaxValidationApiVersion
private val jValidation = "2.0.1.Final"
private val codegen = "2.4.1"
private val codegen = "3.0.0-SNAPSHOT"
object GlobalImport extends GraphQLCodegenKeys {
......@@ -63,8 +63,8 @@ class GraphQLCodegenPlugin(configuration: Configuration, private[codegen] val co
graphqlSchemaPaths := Seq.empty,
graphqlSchemaValidate := Seq.empty,
customTypesMapping := new util.HashMap[String, String](), //TODO use scala Map, convert to java Map
customAnnotationsMapping := new util.HashMap[String, String](),
directiveAnnotationsMapping := new util.HashMap[String, String](),
customAnnotationsMapping := new util.HashMap[String, util.List[String]](),
directiveAnnotationsMapping := new util.HashMap[String, util.List[String]](),
javaxValidationApiVersion := None,
graphqlJavaCodegenVersion := None,
// suffix/prefix/strategies:
......@@ -84,6 +84,8 @@ class GraphQLCodegenPlugin(configuration: Configuration, private[codegen] val co
modelValidationAnnotation := MappingConfigConstants.DEFAULT_VALIDATION_ANNOTATION,
apiReturnType := None,
apiReturnListType := None,
apiInterfaceStrategy := MappingConfigConstants.DEFAULT_API_INTERFACE_STRATEGY,
useOptionalForNullableReturnTypes := MappingConfigConstants.DEFAULT_USE_OPTIONAL_FOR_NULLABLE_RETURN_TYPES,
// package name configs:
apiPackageName := None,
modelPackageName := None,
......@@ -130,7 +132,6 @@ class GraphQLCodegenPlugin(configuration: Configuration, private[codegen] val co
mappingConfig.setGenerateImmutableModels((generateImmutableModels in GraphQLCodegenConfig).value)
mappingConfig.setGenerateToString((generateToString in GraphQLCodegenConfig).value)
mappingConfig.setSubscriptionReturnType((subscriptionReturnType in GraphQLCodegenConfig).value.orNull)
mappingConfig.setGenerateAsyncApi((generateAsyncApi in GraphQLCodegenConfig).value)
mappingConfig.setGenerateParameterizedFieldsResolvers((generateParameterizedFieldsResolvers in GraphQLCodegenConfig).value)
mappingConfig.setGenerateDataFetchingEnvironmentArgumentInApis((generateDataFetchingEnvironmentArgumentInApis in GraphQLCodegenConfig).value)
mappingConfig.setGenerateExtensionFieldsResolvers((generateExtensionFieldsResolvers in GraphQLCodegenConfig).value)
......@@ -146,9 +147,12 @@ class GraphQLCodegenPlugin(configuration: Configuration, private[codegen] val co
mappingConfig.setQueryResolverParentInterface((parentInterfaces in GraphQLCodegenConfig).value.queryResolver)
mappingConfig.setMutationResolverParentInterface((parentInterfaces in GraphQLCodegenConfig).value.mutationResolver)
mappingConfig.setSubscriptionResolverParentInterface((parentInterfaces in GraphQLCodegenConfig).value.subscriptionResolver)
mappingConfig.setApiAsyncReturnType((apiAsyncReturnType in GraphQLCodegenConfig).value)
mappingConfig.setApiAsyncReturnListType((apiAsyncReturnListType in GraphQLCodegenConfig).value.orNull)
mappingConfig.setApiReturnType((apiReturnType in GraphQLCodegenConfig).value.orNull)
mappingConfig.setApiReturnListType((apiReturnListType in GraphQLCodegenConfig).value.orNull)
mappingConfig.setDirectiveAnnotationsMapping((directiveAnnotationsMapping in GraphQLCodegenConfig).value)
mappingConfig.setApiInterfaceStrategy((apiInterfaceStrategy in GraphQLCodegenConfig).value)
mappingConfig.setUseOptionalForNullableReturnTypes((useOptionalForNullableReturnTypes in GraphQLCodegenConfig).value)
sLog.value.debug(s"Current mapping config is <$mappingConfig>")
mappingConfig
}
......
......@@ -41,14 +41,16 @@ customTypesMapping := {
modelNameSuffix := Some("DO")
customAnnotationsMapping := {
val mapping = new util.HashMap[String, String]
val mapping = new util.HashMap[String, util.List[String]]
val annotations = new util.ArrayList[String]()
annotations.add("@com.fasterxml.jackson.annotation.JsonTypeInfo(use=com.fasterxml.jackson.annotation.JsonTypeInfo.Id.NAME, include=com.fasterxml.jackson.annotation.JsonTypeInfo.As.PROPERTY,property = \"__typename\")")
annotations.add("""@com.fasterxml.jackson.annotation.JsonSubTypes(value = {
| @com.fasterxml.jackson.annotation.JsonSubTypes.Type(value = HumanDO.class, name = "Human"),
| @com.fasterxml.jackson.annotation.JsonSubTypes.Type(value = DroidDO.class, name = "Droid")})""".stripMargin)
//must add this annotation
//property is __typename and you must with __typename while invoke, like new CharacterResponseProjection().id().name().typename()
//and in @JsonSubTypes.Type, name is __typename's value
mapping.put("Character",
s"""@com.fasterxml.jackson.annotation.JsonTypeInfo(use=com.fasterxml.jackson.annotation.JsonTypeInfo.Id.NAME, include=com.fasterxml.jackson.annotation.JsonTypeInfo.As.PROPERTY,property = "__typename")${System.lineSeparator()}@com.fasterxml.jackson.annotation.JsonSubTypes(value = {
| @com.fasterxml.jackson.annotation.JsonSubTypes.Type(value = HumanDO.class, name = "Human"),
| @com.fasterxml.jackson.annotation.JsonSubTypes.Type(value = DroidDO.class, name = "Droid")})""".stripMargin)
mapping.put("Character",annotations)//since v3.0.0
mapping
}
......
......@@ -6,7 +6,7 @@ lazy val root = (project in file("."))
scalaVersion := "2.13.2",
apiPackageName := Some("io.github.kobylynskyi.graphql.test.api"),
modelPackageName := Some("io.github.kobylynskyi.graphql.test.model"),
apiReturnType := "scala.concurrent.Future", // if Async class is not at current source, need import dependency
apiReturnType := Some("scala.concurrent.Future"), // if Async class is not at current source, need import dependency
//use full class name is good
).enablePlugins(GraphQLCodegenPlugin).settings(GraphQLCodegenPluginDependencies)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册