Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/codegen-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
| `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. |
| `unknownFieldsPropertyName` | String | userDefinedFields | Specifies the name of the property to be included in api classes to support unknown fields during serialization or deserialization |
| `skip` | Boolean | False | If true, then code generation will not happen |
| `skipSchemaSizeLimit` | Boolean | True | When set to true, the GraphQL schema will be processed with token, character, line and rule depth limits. Set to false to process the schema regardless of its size.
|


### Option `graphqlSchemas`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.kobylynskyi.graphql.codegen.supplier.MappingConfigSupplier;
import com.kobylynskyi.graphql.codegen.supplier.MergeableMappingConfigSupplier;
import com.kobylynskyi.graphql.codegen.supplier.SchemaFinder;
import graphql.parser.ParserOptions;
import org.gradle.api.Action;
import org.gradle.api.DefaultTask;
import org.gradle.api.plugins.JavaPluginExtension;
Expand Down Expand Up @@ -121,6 +122,7 @@ public class GraphQLCodegenGradleTask extends DefaultTask implements GraphQLCode
private String unknownFieldsPropertyName = MappingConfigConstants.DEFAULT_UNKNOWN_FIELDS_PROPERTY_NAME;

private Boolean skip = false;
private Boolean skipSchemaSizeLimit = true;

public GraphQLCodegenGradleTask() {
setGroup("codegen");
Expand Down Expand Up @@ -228,6 +230,15 @@ private GraphQLCodegen instantiateCodegen(MappingConfig mappingConfig) throws IO
GeneratedLanguage language = mappingConfigSupplier.map(Supplier::get)
.map(MappingConfig::getGeneratedLanguage)
.orElse(generatedLanguage);

if (skipSchemaSizeLimit) {
ParserOptions.Builder parserOptionBuilder = ParserOptions.newParserOptions()
.maxTokens(Integer.MAX_VALUE)
.maxCharacters(Integer.MAX_VALUE)
.maxWhitespaceTokens(Integer.MAX_VALUE)
.maxRuleDepth(Integer.MAX_VALUE);
ParserOptions.setDefaultParserOptions(parserOptionBuilder.build());
}
switch (language) {
case JAVA:
return new JavaGraphQLCodegen(getActualSchemaPaths(), graphqlQueryIntrospectionResultPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.kobylynskyi.graphql.codegen.supplier.MappingConfigSupplier;
import com.kobylynskyi.graphql.codegen.supplier.MergeableMappingConfigSupplier;
import com.kobylynskyi.graphql.codegen.supplier.SchemaFinder;
import graphql.parser.ParserOptions;
import org.apache.maven.model.Resource;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
Expand Down Expand Up @@ -248,6 +249,9 @@ public class GraphQLCodegenMojo extends AbstractMojo implements GraphQLCodegenCo
@Parameter(defaultValue = "false")
private boolean skip;

@Parameter(defaultValue = "true")
private boolean skipSchemaSizeLimit;

@Override
public void execute() throws MojoExecutionException {
addCompileSourceRootIfConfigured();
Expand Down Expand Up @@ -338,6 +342,16 @@ private GraphQLCodegen instantiateCodegen(MappingConfig mappingConfig) throws IO
GeneratedLanguage language = mappingConfigSupplier.map(Supplier::get)
.map(MappingConfig::getGeneratedLanguage)
.orElse(generatedLanguage);

if (skipSchemaSizeLimit) {
ParserOptions.Builder parserOptionBuilder = ParserOptions.newParserOptions()
.maxTokens(Integer.MAX_VALUE)
.maxCharacters(Integer.MAX_VALUE)
.maxWhitespaceTokens(Integer.MAX_VALUE)
.maxRuleDepth(Integer.MAX_VALUE);
ParserOptions.setDefaultParserOptions(parserOptionBuilder.build());
}

switch (language) {
case JAVA:
return new JavaGraphQLCodegen(getSchemas(), graphqlQueryIntrospectionResultPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,6 @@ trait GraphQLCodegenKeys {

val supportUnknownFields = settingKey[Boolean]("supportUnknownFields")
val unknownFieldsPropertyName = settingKey[String]("unknownFieldsPropertyName")
val skipSchemaSizeLimit = settingKey[Boolean]("Skip schema size limit checks.")

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.dreamylost.graphql.codegen

import graphql.parser.ParserOptions
import com.kobylynskyi.graphql.codegen.GraphQLCodegenValidate
import com.kobylynskyi.graphql.codegen.java.JavaGraphQLCodegen
import com.kobylynskyi.graphql.codegen.model._
Expand Down Expand Up @@ -131,7 +132,8 @@ class GraphQLCodegenPlugin(configuration: Configuration, private[codegen] val co
unknownFieldsPropertyName := MappingConfigConstants.DEFAULT_UNKNOWN_FIELDS_PROPERTY_NAME,
generateNoArgsConstructorOnly := MappingConfigConstants.DEFAULT_GENERATE_NOARGS_CONSTRUCTOR_ONLY,
generateModelsWithPublicFields := MappingConfigConstants.DEFAULT_GENERATE_MODELS_WITH_PUBLIC_FIELDS,
skip := false
skip := false,
skipSchemaSizeLimit := true
)

private def getMappingConfig(): Def.Initialize[MappingConfig] = Def.setting {
Expand Down Expand Up @@ -247,6 +249,16 @@ class GraphQLCodegenPlugin(configuration: Configuration, private[codegen] val co
graphqlCodegen := {
sLog.value.info(s"Generating files: ${BuildInfo.toString}")
val mappingConfigSupplier = buildJsonSupplier(configurationFiles.value)

if (skipSchemaSizeLimit.value) {
val parserOptionBuilder = ParserOptions
.newParserOptions()
.maxTokens(Integer.MAX_VALUE)
// .maxCharacters(Integer.MAX_VALUE)
.maxWhitespaceTokens(Integer.MAX_VALUE)
.maxRuleDepth(Integer.MAX_VALUE);
ParserOptions.setDefaultParserOptions(parserOptionBuilder.build());
}
val language = mappingConfigSupplier.map(_.get()).map(_.getGeneratedLanguage).getOrElse(generatedLanguage.value)
var result = Seq.empty[File]
try {
Expand Down