未验证 提交 f7fe7ae8 编写于 作者: B Ben McCann 提交者: GitHub

Add more options to the sbt plugin (#122)

上级 5c50d386
......@@ -30,8 +30,21 @@ addSbtPlugin("io.github.kobylynskyi" % "sbt-graphql-java-codegen" % "1.6.0-NOT-Y
| `graphqlSchemaPaths` | List(String) | (falls back to `graphqlSchemas`) | GraphQL schema locations. You can supply multiple paths to GraphQL schemas. To include many schemas from a folder hierarchy, use the `graphqlSchemas` block instead. |
| `graphqlApiPackageName` | String | Empty | Java package for generated api classes (Query, Mutation, Subscription). |
| `graphqlModelPackageName` | String | Empty | Java package for generated model classes (type, input, interface, enum, union). |
| `graphqlGenerateBuilder` | Boolean | True | Specifies whether generated model classes should have builder. |
| `graphqlGenerateApis` | Boolean | True | Specifies whether api classes should be generated as well as model classes. |
| `graphqlGenerateAsyncApi` | Boolean | False | If true, then wrap type into `java.util.concurrent.CompletableFuture` or `subscriptionReturnType` |
| `graphqlGenerateDataFetchingEnvArgInApis` | Boolean | False | If true, then `graphql.schema.DataFetchingEnvironment env` will be added as a last argument to all methods of root type resolvers and field resolvers. |
| `graphqlGenerateEqualsAndHashCode` | Boolean | False | Specifies whether generated model classes should have equals and hashCode methods defined. |
| `graphqlGenerateToString` | Boolean | False | Specifies whether generated model classes should have toString method defined. |
| `graphqlModelNamePrefix` | String | Empty | Sets the prefix for GraphQL model classes (type, input, interface, enum, union). |
| `graphqlModelNameSuffix` | String | Empty | Sets the suffix for GraphQL model classes (type, input, interface, enum, union). |
| `graphqlModelValidationAnnotation` | String | @javax.validation.<br>constraints.NotNull | Annotation for mandatory (NonNull) fields. Can be null/empty. |
| `graphqlGenerateParameterizedFieldsResolvers` | Boolean | True | If true, then generate separate `Resolver` interface for parametrized fields. If false, then add field to the type definition and ignore field parameters. |
| `graphqlGenerateExtensionFieldsResolvers` | Boolean | False | Specifies whether all fields in extensions (<code>extend type</code> and <code>extend interface</code>) should be present in Resolver interface instead of the type class itself. |
| `graphqlGenerateRequests` | Boolean | False | Specifies whether client-side classes should be generated for each query, mutation and subscription. This includes: `Request` class (contains input data) and `ResponseProjection` class (contains response fields). |
| `graphqlRequestSuffix` | String | Request | Sets the suffix for `Request` classes. |
| `graphqlResponseProjectionSuffix` | String | ResponseProjection | Sets the suffix for `ResponseProjection` classes. |
### Different configurations for graphql schemas
......
package io.github.kobylynskyi.graphql.codegen
import com.kobylynskyi.graphql.codegen.GraphQLCodegen
import com.kobylynskyi.graphql.codegen.model.DefaultMappingConfigValues;
import com.kobylynskyi.graphql.codegen.model.MappingConfig
import com.kobylynskyi.graphql.codegen.supplier.MappingConfigSupplier
import com.kobylynskyi.graphql.codegen.supplier.SchemaFinder
......@@ -20,6 +21,19 @@ object GraphQLCodegenSbtPlugin extends AutoPlugin {
val graphqlModelNameSuffix = settingKey[String]("Suffix to append to the model class names.")
val graphqlApiPackageName = settingKey[String]("Java package to use when generating the API classes.")
val graphqlModelPackageName = settingKey[String]("Java package to use when generating the model classes.")
val graphqlGenerateBuilder = settingKey[Boolean]("Specifies whether generated model classes should have builder.")
val graphqlGenerateApis = settingKey[Boolean]("Specifies whether api classes should be generated as well as model classes.")
val graphqlGenerateEqualsAndHashCode = settingKey[Boolean]("Specifies whether generated model classes should have equals and hashCode methods defined.")
val graphqlGenerateToString = settingKey[Boolean]("Specifies whether generated model classes should have toString method defined.")
val graphqlGenerateAsyncApi = settingKey[Boolean]("If true, then wrap type into java.util.concurrent.CompletableFuture or subscriptionReturnType")
val graphqlModelValidationAnnotation = settingKey[String]("Annotation for mandatory (NonNull) fields. Can be null/empty.")
val graphqlGenerateParameterizedFieldsResolvers = settingKey[Boolean]("If true, then generate separate Resolver interface for parametrized fields. If false, then add field to the type definition and ignore field parameters.")
val graphqlGenerateExtensionFieldsResolvers = settingKey[Boolean]("Specifies whether all fields in extensions (extend type and extend interface) should be present in Resolver interface instead of the type class itself.")
val graphqlGenerateDataFetchingEnvArgInApis = settingKey[Boolean]("If true, then graphql.schema.DataFetchingEnvironment env will be added as a last argument to all methods of root type resolvers and field resolvers.")
val graphqlGenerateRequests = settingKey[Boolean]("Specifies whether client-side classes should be generated for each query, mutation and subscription. This includes: Request class (contains input data) and ResponseProjection class (contains response fields).")
val graphqlRequestSuffix = settingKey[String]("Specifies whether client-side classes should be generated for each query, mutation and subscription. This includes: Request class (contains input data) and ResponseProjection class (contains response fields).")
val graphqlResponseProjectionSuffix = settingKey[String]("Specifies whether client-side classes should be generated for each query, mutation and subscription. This includes: Request class (contains input data) and ResponseProjection class (contains response fields).")
// default values for the tasks and settings
lazy val baseGraphQLSettings: Seq[Def.Setting[_]] = Seq(
......@@ -31,10 +45,34 @@ object GraphQLCodegenSbtPlugin extends AutoPlugin {
(graphqlModelNamePrefix in graphql).value,
(graphqlModelNameSuffix in graphql).value,
(graphqlApiPackageName in graphql).value,
(graphqlModelPackageName in graphql).value
(graphqlModelPackageName in graphql).value,
(graphqlGenerateBuilder in graphql).value,
(graphqlGenerateApis in graphql).value,
(graphqlModelValidationAnnotation in graphql).value,
(graphqlGenerateEqualsAndHashCode in graphql).value,
(graphqlGenerateToString in graphql).value,
(graphqlGenerateAsyncApi in graphql).value,
(graphqlGenerateParameterizedFieldsResolvers in graphql).value,
(graphqlGenerateExtensionFieldsResolvers in graphql).value,
(graphqlGenerateDataFetchingEnvArgInApis in graphql).value,
(graphqlGenerateRequests in graphql).value,
(graphqlRequestSuffix in graphql).value,
(graphqlResponseProjectionSuffix in graphql).value
)
},
graphqlSchemaPaths in graphql := Seq((sourceDirectory.value / "resources/schema.graphql").getCanonicalPath),
graphqlGenerateBuilder in graphql := DefaultMappingConfigValues.DEFAULT_BUILDER,
graphqlGenerateApis in graphql := DefaultMappingConfigValues.DEFAULT_GENERATE_APIS,
graphqlModelValidationAnnotation in graphql := DefaultMappingConfigValues.DEFAULT_VALIDATION_ANNOTATION,
graphqlGenerateEqualsAndHashCode in graphql := DefaultMappingConfigValues.DEFAULT_EQUALS_AND_HASHCODE,
graphqlGenerateToString in graphql := DefaultMappingConfigValues.DEFAULT_TO_STRING,
graphqlGenerateAsyncApi in graphql := DefaultMappingConfigValues.DEFAULT_GENERATE_ASYNC_APIS,
graphqlGenerateParameterizedFieldsResolvers in graphql := DefaultMappingConfigValues.DEFAULT_GENERATE_PARAMETERIZED_FIELDS_RESOLVERS,
graphqlGenerateExtensionFieldsResolvers in graphql := DefaultMappingConfigValues.DEFAULT_GENERATE_EXTENSION_FIELDS_RESOLVERS,
graphqlGenerateDataFetchingEnvArgInApis in graphql := DefaultMappingConfigValues.DEFAULT_GENERATE_DATA_FETCHING_ENV,
graphqlGenerateRequests in graphql := DefaultMappingConfigValues.DEFAULT_GENERATE_REQUESTS,
graphqlRequestSuffix in graphql := DefaultMappingConfigValues.DEFAULT_REQUEST_SUFFIX,
graphqlResponseProjectionSuffix in graphql := DefaultMappingConfigValues.DEFAULT_RESPONSE_PROJECTION_SUFFIX,
// This follows the output directory structure recommended by sbt team
// https://github.com/sbt/sbt/issues/1664#issuecomment-213057686
......@@ -64,13 +102,37 @@ object Codegen {
graphqlModelNamePrefix: String,
graphqlModelNameSuffix: String,
graphqlApiPackageName: String,
graphqlModelPackageName: String): Seq[File] = {
graphqlModelPackageName: String,
graphqlGenerateBuilder: Boolean,
graphqlGenerateApis: Boolean,
graphqlModelValidationAnnotation: String,
graphqlGenerateEqualsAndHashCode: Boolean,
graphqlGenerateToString: Boolean,
graphqlGenerateAsyncApi: Boolean,
graphqlGenerateParameterizedFieldsResolvers: Boolean,
graphqlGenerateExtensionFieldsResolvers: Boolean,
graphqlGenerateDataFetchingEnvArgInApis: Boolean,
graphqlGenerateRequests: Boolean,
graphqlRequestSuffix: String,
graphqlResponseProjectionSuffix: String): Seq[File] = {
val mappingConfig = new MappingConfig();
mappingConfig.setModelNamePrefix(graphqlModelNamePrefix);
mappingConfig.setModelNameSuffix(graphqlModelNameSuffix);
mappingConfig.setApiPackageName(graphqlApiPackageName);
mappingConfig.setModelPackageName(graphqlModelPackageName);
mappingConfig.setGenerateBuilder(graphqlGenerateBuilder);
mappingConfig.setGenerateApis(graphqlGenerateApis);
mappingConfig.setModelValidationAnnotation(graphqlModelValidationAnnotation);
mappingConfig.setGenerateEqualsAndHashCode(graphqlGenerateEqualsAndHashCode);
mappingConfig.setGenerateToString(graphqlGenerateToString);
mappingConfig.setGenerateAsyncApi(graphqlGenerateAsyncApi);
mappingConfig.setGenerateParameterizedFieldsResolvers(graphqlGenerateParameterizedFieldsResolvers);
mappingConfig.setGenerateExtensionFieldsResolvers(graphqlGenerateExtensionFieldsResolvers);
mappingConfig.setGenerateDataFetchingEnvironmentArgumentInApis(graphqlGenerateDataFetchingEnvArgInApis);
mappingConfig.setGenerateRequests(graphqlGenerateRequests);
mappingConfig.setRequestSuffix(graphqlRequestSuffix);
mappingConfig.setResponseProjectionSuffix(graphqlResponseProjectionSuffix);
val mappingConfigSupplier = null;
val generatedSources = new GraphQLCodegen(getSchemas(graphqlSchemaPaths, schemasRootDir), outputDir, mappingConfig, mappingConfigSupplier).generate();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册