Class GenerateServerCodeTask
- All Implemented Interfaces:
com.graphql_java_generator.plugin.conf.CommonConfiguration,com.graphql_java_generator.plugin.conf.GenerateCodeCommonConfiguration,com.graphql_java_generator.plugin.conf.GenerateServerCodeConfiguration,Comparable<org.gradle.api.Task>,org.gradle.api.internal.DynamicObjectAware,org.gradle.api.internal.TaskInternal,org.gradle.api.plugins.ExtensionAware,org.gradle.api.Task,org.gradle.util.Configurable<org.gradle.api.Task>
- Direct Known Subclasses:
GraphQLGenerateCodeTask
The generateServerCode Maven goal (and Gradle task) generates the java code for an almost ready to start GraphQL server. The developer has only to develop request to the data.
The java code is generated from one or more GraphQL schemas. It allows to work in Java with graphQL, in a schema first approach. These items are generated:
- the main method (in a jar project) or the main servlet (in a war project)
- All the GraphQL wiring, based on graphql-java-spring, itself being build on top of graphql-java
- All the POJOs, that contain the incoming request contents. The request response is written by the user code into these POJO, and the plugin take care of mapping them into the server response.
- An option allows to annotate the POJOs with the standard JPA annotations, to make it easy to link with a database. Please note that a
- All the interfaces for the
DataFetchersDelegate(named providers in the graphql.org presentation) that the server needs to implement
The specific code that needs to be implemented is the access to the Data: your database, other APIs or web services,
or any kind of storage you may have. This is done by implementing the interfaces for the DataFetchersDelegate
into a Spring component, that is:
- Create a class for each generated
DataFetchersDelegateinterface - Make it implement the relevant
DataFetchersDelegateinterface - Mark it with the
Componentannotation
And you're done! :)
You'll find more info in the tutorials: take a look at the Maven server tutorial or the Gradle server tutorial
Note: The attribute have no default values: their default values is read from the
GenerateCodeCommonExtension, whose attributes can be either the default value, or a value set in the build
script.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.gradle.api.Task
org.gradle.api.Task.Namer -
Field Summary
FieldsModifier and TypeFieldDescriptionThe javaTypeForIDType is the java class that is used in the generated code for GraphQL fields that are of the GraphQL ID type.Fields inherited from class com.graphql_java_generator.gradleplugin.GenerateCodeCommonTask
targetResourceFolder, targetSourceFolder, useJakartaEE9Fields inherited from class com.graphql_java_generator.gradleplugin.CommonTask
extension, extensionClass, skipGenerationIfSchemaHasNotChangedFields inherited from interface com.graphql_java_generator.plugin.conf.CommonConfiguration
DEFAULT_ADD_RELAY_CONNECTIONS, DEFAULT_MAX_TOKENS, DEFAULT_PACKAGE_NAME, DEFAULT_PREFIX, DEFAULT_SCHEMA_FILE_FOLDER, DEFAULT_SCHEMA_FILE_PATTERN, DEFAULT_SCHEMA_SUB_FOLDER, DEFAULT_SKIP_GENERATION_IF_SCHEMA_HAS_NOT_CHANGED, DEFAULT_SUFFIXFields inherited from interface com.graphql_java_generator.plugin.conf.GenerateCodeCommonConfiguration
DEFAULT_COPY_RUNTIME_SOURCES, DEFAULT_QUERY_MUTATION_EXECUTION_PROTOCOL, DEFAULT_SCHEMA_PERSONALIZATION_FILE, DEFAULT_SEPARATE_UTIL_CLASSES, DEFAULT_SOURCE_ENCODING, DEFAULT_SPRING_BEAN_SUFFIX, DEFAULT_TARGET_RESOURCE_FOLDER, DEFAULT_TARGET_SOURCE_FOLDER, DEFAULT_USE_JAKARTA_EE9Fields inherited from interface com.graphql_java_generator.plugin.conf.GenerateServerCodeConfiguration
DEFAULT_GENERATE_BATCH_LOADER_ENVIRONMENT, DEFAULT_GENERATE_DATA_LOADER_FOR_LISTS, DEFAULT_GENERATE_JPA_ANNOTATION, DEFAULT_JAVA_TYPE_FOR_ID_TYPE, DEFAULT_SCAN_BASE_PACKAGESFields inherited from interface org.gradle.api.Task
TASK_ACTION, TASK_CONSTRUCTOR_ARGS, TASK_DEPENDS_ON, TASK_DESCRIPTION, TASK_GROUP, TASK_NAME, TASK_OVERWRITE, TASK_TYPE -
Constructor Summary
ConstructorsConstructorDescriptionGenerateServerCodeTask(Class<? extends GenerateServerCodeExtension> extensionClazz) -
Method Summary
Modifier and TypeMethodDescriptionvoidexecute()protected GenerateServerCodeExtensionfinal Stringcom.graphql_java_generator.plugin.conf.PluginModegetMode()final com.graphql_java_generator.plugin.conf.Packagingfinal Stringfinal booleanbooleanbooleanfinal booleanfinal voidsetGenerateBatchLoaderEnvironment(boolean generateBatchLoaderEnvironment) final voidsetGenerateDataLoaderForLists(boolean generateDataLoaderForLists) final voidsetGenerateJPAAnnotation(boolean generateJPAAnnotation) final voidsetJavaTypeForIDType(String javaTypeForIDType) final voidsetScanBasePackages(String scanBasePackages) Methods inherited from class com.graphql_java_generator.gradleplugin.GenerateCodeCommonTask
getCustomScalars, getPackageName, getQueryMutationExecutionProtocol, getSchemaPersonalizationFile, getSourceEncoding, getSpringAutoConfigurationPackage, getSpringBeanSuffix, getTargetClassFolder, getTargetResourceFolder, getTargetSourceFolder, isCopyRuntimeSources, isGenerateUtilityClasses, isSeparateUtilityClasses, isUseJakartaEE9, registerGeneratedFolders, setCopyRuntimeSources, setCustomScalars, setPackageName, setQueryMutationExecutionProtocol, setSchemaPersonalizationFile, setSeparateUtilityClasses, setSourceEncoding, setSpringBeanSuffix, setTargetResourceFolder, setTargetSourceFolder, setUseJakartaEE9Methods inherited from class com.graphql_java_generator.gradleplugin.CommonTask
addThisTaskAsADependencyToAnotherTask, configure, getDefaultTargetSchemaFileName, getEnumPrefix, getEnumSuffix, getFileValue, getInputPrefix, getInputSuffix, getInterfacePrefix, getInterfaceSuffix, getMaxTokens, getProjectDir, getSchemaFileFolder, getSchemaFilePattern, getTargetSchemaSubFolder, getTemplates, getTypePrefix, getTypeSuffix, getUnionPrefix, getUnionSuffix, getValue, isAddRelayConnections, isInitialized, isSkipGenerationIfSchemaHasNotChanged, logConfiguration, setAddRelayConnections, setEnumPrefix, setEnumSuffix, setInitialized, setInputPrefix, setInputSuffix, setInterfacePrefix, setInterfaceSuffix, setParserOptions, setSchemaFileFolder, setSchemaFilePattern, setSkipGenerationIfSchemaHasNotChanged, setTemplates, setTypePrefix, setTypeSuffix, setUnionPrefix, setUnionSuffixMethods inherited from class org.gradle.api.DefaultTask
compareTo, dependsOn, doFirst, doFirst, doFirst, doLast, doLast, doLast, finalizedBy, getActions, getAnt, getDependsOn, getDescription, getDestroyables, getDidWork, getEnabled, getExtensions, getFinalizedBy, getGroup, getInputs, getLocalState, getLogger, getLogging, getMustRunAfter, getName, getOutputs, getPath, getProject, getShouldRunAfter, getState, getTaskDependencies, getTemporaryDir, getTimeout, hasProperty, mustRunAfter, onlyIf, onlyIf, onlyIf, property, setActions, setDependsOn, setDescription, setDidWork, setEnabled, setFinalizedBy, setGroup, setMustRunAfter, setOnlyIf, setOnlyIf, setOnlyIf, setProperty, setShouldRunAfter, shouldRunAfter, usesServiceMethods inherited from class org.gradle.api.internal.AbstractTask
appendParallelSafeAction, doNotTrackState, getAsDynamicObject, getConvention, getIdentityPath, getImpliesSubProjects, getLifecycleDependencies, getOnlyIf, getReasonNotToTrackState, getReasonTaskIsIncompatibleWithConfigurationCache, getRequiredServices, getServices, getSharedResources, getStandardOutputCapture, getTaskActions, getTaskIdentity, getTemporaryDirFactory, hasTaskActions, injectIntoNewInstance, isCompatibleWithConfigurationCache, isEnabled, isHasCustomActions, notCompatibleWithConfigurationCache, prependParallelSafeAction, setImpliesSubProjectsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.graphql_java_generator.plugin.conf.CommonConfiguration
getDefaultTargetSchemaFileName, getEnumPrefix, getEnumSuffix, getInputPrefix, getInputSuffix, getInterfacePrefix, getInterfaceSuffix, getMaxTokens, getProjectDir, getSchemaFileFolder, getSchemaFilePattern, getTargetSchemaSubFolder, getTemplates, getTypePrefix, getTypeSuffix, getUnionPrefix, getUnionSuffix, isAddRelayConnections, isSkipGenerationIfSchemaHasNotChanged, logCommonConfigurationMethods inherited from interface com.graphql_java_generator.plugin.conf.GenerateCodeCommonConfiguration
getCustomScalars, getPackageName, getQueryMutationExecutionProtocol, getSchemaPersonalizationFile, getSourceEncoding, getSpringAutoConfigurationPackage, getSpringBeanSuffix, getTargetClassFolder, getTargetResourceFolder, getTargetSourceFolder, isCopyRuntimeSources, isGenerateUtilityClasses, isSeparateUtilityClasses, isUseJakartaEE9, logGenerateCodeCommonConfigurationMethods inherited from interface com.graphql_java_generator.plugin.conf.GenerateServerCodeConfiguration
logConfiguration, logGenerateServerCodeConfigurationMethods inherited from interface org.gradle.api.Task
doNotTrackState, getConvention, notCompatibleWithConfigurationCache
-
Field Details
-
javaTypeForIDType
The javaTypeForIDType is the java class that is used in the generated code for GraphQL fields that are of the GraphQL ID type. The default value is java.util.UUID. Valid values are: java.lang.String, java.lang.Long and java.util.UUID.
This parameter is only valid for the server mode. When generating the client code, the ID is always generated as a String type, as recommended in the GraphQL doc.
In other words: when in server mode and javaTypeForIDType is not set, all GraphQL ID fields are UUID attributes in java. When in server mode and javaTypeForIDType is set to the X type, all GraphQL ID fields are X attributes in java.
Note: you can override this, by using the schema personalization capability. For more information, please have a look at the Schema Personalization doc page.
-
-
Constructor Details
-
GenerateServerCodeTask
@Inject public GenerateServerCodeTask() -
GenerateServerCodeTask
-
-
Method Details
-
execute
- Throws:
IOException
-
getJavaTypeForIDType
- Specified by:
getJavaTypeForIDTypein interfacecom.graphql_java_generator.plugin.conf.GenerateServerCodeConfiguration
-
setJavaTypeForIDType
-
getMode
@Input public com.graphql_java_generator.plugin.conf.PluginMode getMode()- Specified by:
getModein interfacecom.graphql_java_generator.plugin.conf.GenerateCodeCommonConfiguration- Overrides:
getModein classGenerateCodeCommonTask
-
getPackaging
@Internal public final com.graphql_java_generator.plugin.conf.Packaging getPackaging()- Specified by:
getPackagingin interfacecom.graphql_java_generator.plugin.conf.GenerateServerCodeConfiguration
-
getQuotedScanBasePackages
- Specified by:
getQuotedScanBasePackagesin interfacecom.graphql_java_generator.plugin.conf.GenerateServerCodeConfiguration
-
getScanBasePackages
- Specified by:
getScanBasePackagesin interfacecom.graphql_java_generator.plugin.conf.GenerateServerCodeConfiguration
-
setScanBasePackages
-
isGenerateBatchLoaderEnvironment
@Input public final boolean isGenerateBatchLoaderEnvironment()- Specified by:
isGenerateBatchLoaderEnvironmentin interfacecom.graphql_java_generator.plugin.conf.GenerateServerCodeConfiguration
-
setGenerateBatchLoaderEnvironment
public final void setGenerateBatchLoaderEnvironment(boolean generateBatchLoaderEnvironment) -
isGenerateJacksonAnnotations
@Internal public boolean isGenerateJacksonAnnotations()- Specified by:
isGenerateJacksonAnnotationsin interfacecom.graphql_java_generator.plugin.conf.CommonConfiguration- Specified by:
isGenerateJacksonAnnotationsin interfacecom.graphql_java_generator.plugin.conf.GenerateServerCodeConfiguration- Overrides:
isGenerateJacksonAnnotationsin classGenerateCodeCommonTask
-
isGenerateJPAAnnotation
@Input public final boolean isGenerateJPAAnnotation()- Specified by:
isGenerateJPAAnnotationin interfacecom.graphql_java_generator.plugin.conf.GenerateServerCodeConfiguration
-
setGenerateJPAAnnotation
public final void setGenerateJPAAnnotation(boolean generateJPAAnnotation) -
isGenerateDataLoaderForLists
@Input public boolean isGenerateDataLoaderForLists()- Specified by:
isGenerateDataLoaderForListsin interfacecom.graphql_java_generator.plugin.conf.GenerateServerCodeConfiguration
-
setGenerateDataLoaderForLists
public final void setGenerateDataLoaderForLists(boolean generateDataLoaderForLists) -
getExtension
- Overrides:
getExtensionin classGenerateCodeCommonTask
-