Class AbstractGenerateServerCodeMojo
- All Implemented Interfaces:
CommonConfiguration,GenerateCodeCommonConfiguration,GenerateServerCodeConfiguration,org.apache.maven.plugin.ContextEnabled,org.apache.maven.plugin.Mojo
- Direct Known Subclasses:
AbstractGraphQLMojo,GenerateServerCodeMojo
public abstract class AbstractGenerateServerCodeMojo extends AbstractGenerateCodeCommonMojo implements GenerateServerCodeConfiguration
GenerateServerCodeMojo and
the GraphQLMojo mojos. It contains all parameters that are common to these goals. The parameters common to
all goal are inherited from the AbstractGenerateCodeCommonMojo class.This avoids to redeclare each common parameter in each Mojo, including its comment. When a comment is updated, only one update is necessary, instead of updating it in each
- Author:
- etienne-sf
-
Field Summary
Fields Modifier and Type Field Description booleangenerateBatchLoaderEnvironment(only for server mode) Indicates if the plugin should generate add theBatchLoaderEnvironmentparameter to the batchLoader methods, in DataFetchersDelegate.java.lang.StringjavaTypeForIDTypeThe 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.mavenplugin.AbstractCommonMojo
buildContext, ctx, enumPrefix, enumSuffix, inputPrefix, inputSuffix, interfacePrefix, interfaceSuffix, maxTokens, projectHelper, springConfigurationClass, typePrefix, typeSuffix, unionPrefix, unionSuffixFields 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_SKIP_GENERATION_IF_SCHEMA_HAS_NOT_CHANGED, DEFAULT_SUFFIXFields inherited from interface com.graphql_java_generator.plugin.conf.GenerateCodeCommonConfiguration
DEFAULT_COPY_RUNTIME_SOURCES, DEFAULT_SEPARATE_UTIL_CLASSES, DEFAULT_SOURCE_ENCODING, DEFAULT_SPRING_BEAN_SUFFIX, DEFAULT_TARGET_RESOURCE_FOLDER, DEFAULT_TARGET_SOURCE_FOLDERFields 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_PACKAGES, DEFAULT_SCHEMA_PERSONALIZATION_FILE -
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractGenerateServerCodeMojo(java.lang.Class<?> springConfigurationClass) -
Method Summary
Modifier and Type Method Description java.lang.StringgetJavaTypeForIDType()PluginModegetMode()The mode is forced toPluginMode.serverPackaginggetPackaging()java.lang.StringgetScanBasePackages()java.io.FilegetSchemaPersonalizationFile()booleanisGenerateBatchLoaderEnvironment()booleanisGenerateDataLoaderForLists()booleanisGenerateJPAAnnotation()Methods inherited from class com.graphql_java_generator.mavenplugin.AbstractGenerateCodeCommonMojo
executePostExecutionTask, getCustomScalars, getPackageName, getSourceEncoding, getSpringBeanSuffix, getTargetClassFolder, getTargetFolder, getTargetResourceFolder, getTargetSourceFolder, isAddRelayConnections, isCopyRuntimeSources, isSeparateUtilityClassesMethods inherited from class com.graphql_java_generator.mavenplugin.AbstractCommonMojo
execute, getEnumPrefix, getEnumSuffix, getInputPrefix, getInputSuffix, getInterfacePrefix, getInterfaceSuffix, getMaxTokens, getProjectDir, getSchemaFileFolder, getSchemaFilePattern, getTemplates, getTypePrefix, getTypeSuffix, getUnionPrefix, getUnionSuffix, isSkipGenerationIfSchemaHasNotChangedMethods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContextMethods 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, getTemplates, getTypePrefix, getTypeSuffix, getUnionPrefix, getUnionSuffix, isAddRelayConnections, isSkipGenerationIfSchemaHasNotChanged, logCommonConfigurationMethods inherited from interface com.graphql_java_generator.plugin.conf.GenerateCodeCommonConfiguration
getCustomScalars, getPackageName, getSourceEncoding, getSpringAutoConfigurationPackage, getSpringBeanSuffix, getTargetClassFolder, getTargetResourceFolder, getTargetSourceFolder, isCopyRuntimeSources, isGenerateUtilityClasses, isSeparateUtilityClasses, logGenerateCodeCommonConfigurationMethods inherited from interface com.graphql_java_generator.plugin.conf.GenerateServerCodeConfiguration
getQuotedScanBasePackages, isGenerateJacksonAnnotations, logConfiguration, logGenerateServerCodeConfiguration
-
Field Details
-
generateBatchLoaderEnvironment
@Parameter(property="com.graphql_java_generator.mavenplugin.generateBatchLoaderEnvironment", defaultValue="false") public boolean generateBatchLoaderEnvironment(only for server mode) Indicates if the plugin should generate add the
BatchLoaderEnvironmentparameter to the batchLoader methods, in DataFetchersDelegate. This parameter allows to get the context of the Batch Loader, including the context associated to the id, when using the id has been added by theDataLoader.load(Object, Object)method.For instance, if you have the method below, for a field named oneWithIdSubType in a DataFetcherDelegate:
@Override public CompletableFuture<AllFieldCasesWithIdSubtype> oneWithIdSubType( DataFetchingEnvironment dataFetchingEnvironment, DataLoader<UUID, AllFieldCasesWithIdSubtype> dataLoader, AllFieldCases source, Boolean uppercase) { return dataLoader.load(UUID.randomUUID()); }then, in the AllFieldCasesWithIdSubtype DataFetcherDelegate, you can retrieve the uppercase this way:
@Override public List<AllFieldCasesWithIdSubtype> batchLoader(List<UUID> keys, BatchLoaderEnvironment environment) { List<AllFieldCasesWithIdSubtype> list = new ArrayList<>(keys.size()); for (UUID id : keys) { // Let's manage the uppercase parameter, that was associated with this key Boolean uppercase = (Boolean) environment.getKeyContexts().get(id); if (uppercase != null && uppercase) { item.setName(item.getName().toUpperCase()); } // Do something with the id and the uppercase value } return list; }For more complex cases, you can store a
Mapwith all the needed values, instead of just the parameter value.Default value is false
-
javaTypeForIDType
@Parameter(property="com.graphql_java_generator.mavenplugin.javaTypeForIDType", defaultValue="java.util.UUID") public java.lang.String javaTypeForIDTypeThe 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
-
AbstractGenerateServerCodeMojo
protected AbstractGenerateServerCodeMojo(java.lang.Class<?> springConfigurationClass)
-
-
Method Details
-
getJavaTypeForIDType
public java.lang.String getJavaTypeForIDType()- Specified by:
getJavaTypeForIDTypein interfaceGenerateServerCodeConfiguration
-
getMode
The mode is forced toPluginMode.server- Specified by:
getModein interfaceGenerateCodeCommonConfiguration
-
getPackaging
- Specified by:
getPackagingin interfaceGenerateServerCodeConfiguration
-
getSchemaPersonalizationFile
public java.io.File getSchemaPersonalizationFile()- Specified by:
getSchemaPersonalizationFilein interfaceGenerateServerCodeConfiguration
-
isGenerateBatchLoaderEnvironment
public boolean isGenerateBatchLoaderEnvironment()- Specified by:
isGenerateBatchLoaderEnvironmentin interfaceGenerateServerCodeConfiguration
-
isGenerateJPAAnnotation
public boolean isGenerateJPAAnnotation()- Specified by:
isGenerateJPAAnnotationin interfaceGenerateServerCodeConfiguration
-
isGenerateDataLoaderForLists
public boolean isGenerateDataLoaderForLists()- Specified by:
isGenerateDataLoaderForListsin interfaceGenerateServerCodeConfiguration
-
getScanBasePackages
public java.lang.String getScanBasePackages()- Specified by:
getScanBasePackagesin interfaceGenerateServerCodeConfiguration
-