Class CommonExtension
- All Implemented Interfaces:
com.graphql_java_generator.plugin.conf.CommonConfiguration
- Direct Known Subclasses:
GenerateCodeCommon,GenerateGraphQLSchemaExtension
public class CommonExtension
extends java.lang.Object
implements com.graphql_java_generator.plugin.conf.CommonConfiguration
This class contain the parameters that are common to all Gradle Extensions for this plugin, that is the parameters that are common to all the tasks of this plugin.
This avoids to redeclare each common parameter in each Extension, including its comment. When a comment is updated, only one update is necessary, instead of updating it in each Extension.
-
Field Summary
Fields Modifier and Type Field Description booleanaddRelayConnectionsTrue if the plugin is configured to add the relay connection capabilities, as described here and specified in the relay connection specification.protected org.gradle.api.ProjectprojectbooleanskipGenerationIfSchemaHasNotChanged(this parameter is in beta version) If true, and the generated sources or resources are older than the GraphQL schema file(s), then there is no source or resource generation. -
Constructor Summary
Constructors Constructor Description CommonExtension(org.gradle.api.Project project) -
Method Summary
Modifier and Type Method Description com.graphql_java_generator.plugin.conf.LoggergetPluginLogger()java.io.FilegetSchemaFileFolder()java.lang.StringgetSchemaFilePattern()java.util.Map<java.lang.String,java.lang.String>getTemplates()booleanisAddRelayConnections()booleanisSkipGenerationIfSchemaHasNotChanged()voidlogConfiguration()voidsetAddRelayConnections(java.lang.Boolean addRelayConnections)voidsetSchemaFileFolder(java.lang.String schemaFileFolder)voidsetSchemaFilePattern(java.lang.String schemaFilePattern)voidsetSkipGenerationIfSchemaHasNotChanged(boolean skipGenerationIfSchemaHasNotChanged)voidsetTemplates(java.util.Map<java.lang.String,java.lang.String> templates)
-
Field Details
-
project
protected final org.gradle.api.Project project -
addRelayConnections
public boolean addRelayConnectionsTrue if the plugin is configured to add the relay connection capabilities, as described here and specified in the relay connection specification.
The plugin reads the GraphQL schema file(s), and enrich them with the interface and types needed to respect the Relay Connection specification. The entry point for that is the @RelayConnection directive. It is specific to this plugin. It can be added to any field, that is, typically: queries, mutations, interface's fields, type's field. It must be declared in the given GraphQL schema file(s) like this:
directive @RelayConnection on FIELD_DEFINITION
When addRelayConnections is set to true, here is what's done for each field that is marked with the @RelayConnection directive:
- The field type, whether it's a list or not, is replaced by the relevant XxxConnection type. For instance the
query allHumans(criteria: String): [Human] @RelayConnection is replaced by allHumans(criteria:
String): HumanConnection, and the human's field friends: Character @RelayConnection is replaced
by friends: CharacterConnection. Please note that :
- The @RelayConnection directive is removed in the target schema
- If the @RelayConnection is set on a field of an interface, it should be set also in the same field, for each type that implements this interface. If not, a warning is generated. The directive is applied on the interface and its implementations's field, whether or not the directive is actually set in the implementing classes.
- If the @RelayConnection is not set on a field of an interface, but is set in the same field, for one type that implements this interface, then an error is generated. The directive is applied on the interface and its implementations's field, whether or not the directive is actually set in the implementing classes.
- Input type's fields may not have the @RelayConnection directive
- For each type marked at least once, with the @RelayConnection directive (the Human type, and the Character interface, here above), the relevant XxxConnection and XxxEdge type are added to the in-memory schema.
- The Node interface is added to each type marked at least once, with the @RelayConnection directive (the Human type, and the Character interface, here above). Of course, these types must have a mandatory field id of type ID that is not a list. If not, then an error is thrown.
As a sum-up, if addRelayConnections is set to true, the plugin will add into the in-memory GraphQL schema:
- Check that the @@RelayConnexion directive definition exist in the GraphQL schema, and is compliant with the above definition.
- Add the Node interface in the GraphQL schema (if not already defined). If this interface is already defined in the given schema, but is not compliant with the relay specification, then an error is thrown.
- Add the PageInfo type in the GraphQL schema (if not already defined). If this type is already defined in the given schema, but is not compliant with the relay specification, then an error is thrown.
- All the Edge and Connection type in the GraphQL schema, for each type that is marked by the @@RelayConnexion directive.
- The field type, whether it's a list or not, is replaced by the relevant XxxConnection type. For instance the
query allHumans(criteria: String): [Human] @RelayConnection is replaced by allHumans(criteria:
String): HumanConnection, and the human's field friends: Character @RelayConnection is replaced
by friends: CharacterConnection. Please note that :
-
skipGenerationIfSchemaHasNotChanged
public boolean skipGenerationIfSchemaHasNotChanged(this parameter is in beta version) If true, and the generated sources or resources are older than the GraphQL schema file(s), then there is no source or resource generation.
For instance, the generateGraphQLSchema goal won't (re)generate the target schema, and the generateClientCode won't generate the sources.
Please note that if your pom adds the generated source folder with the build-helper-maven-plugin, it seems that the compiler will always compile the sources, even if they didn't change. If you still want to use this build-helper-maven-plugin, you'll have to put it into a dedicated profile, so that you can activate it or not as you want. You can have a look at the Issue 69 for a hint on this.
Of course, after a clean goal/taks execution, the target folder won't exist, and the sources or resources will be created again during the next build.
As of 1.x version of the plugin, the default value is false, so that only people aware of it try it. Starting from 2.x version, its default value will be true.
-
-
Constructor Details
-
CommonExtension
public CommonExtension(org.gradle.api.Project project)
-
-
Method Details
-
getPluginLogger
public com.graphql_java_generator.plugin.conf.Logger getPluginLogger()- Specified by:
getPluginLoggerin interfacecom.graphql_java_generator.plugin.conf.CommonConfiguration
-
isAddRelayConnections
public boolean isAddRelayConnections()- Specified by:
isAddRelayConnectionsin interfacecom.graphql_java_generator.plugin.conf.CommonConfiguration
-
setAddRelayConnections
public void setAddRelayConnections(java.lang.Boolean addRelayConnections) -
isSkipGenerationIfSchemaHasNotChanged
public boolean isSkipGenerationIfSchemaHasNotChanged()- Specified by:
isSkipGenerationIfSchemaHasNotChangedin interfacecom.graphql_java_generator.plugin.conf.CommonConfiguration
-
setSkipGenerationIfSchemaHasNotChanged
public void setSkipGenerationIfSchemaHasNotChanged(boolean skipGenerationIfSchemaHasNotChanged) -
getSchemaFileFolder
public java.io.File getSchemaFileFolder()- Specified by:
getSchemaFileFolderin interfacecom.graphql_java_generator.plugin.conf.CommonConfiguration
-
setSchemaFileFolder
public void setSchemaFileFolder(java.lang.String schemaFileFolder) -
getSchemaFilePattern
public java.lang.String getSchemaFilePattern()- Specified by:
getSchemaFilePatternin interfacecom.graphql_java_generator.plugin.conf.CommonConfiguration
-
setSchemaFilePattern
public void setSchemaFilePattern(java.lang.String schemaFilePattern) -
getTemplates
public java.util.Map<java.lang.String,java.lang.String> getTemplates()- Specified by:
getTemplatesin interfacecom.graphql_java_generator.plugin.conf.CommonConfiguration
-
setTemplates
public void setTemplates(java.util.Map<java.lang.String,java.lang.String> templates) -
logConfiguration
public void logConfiguration()- Specified by:
logConfigurationin interfacecom.graphql_java_generator.plugin.conf.CommonConfiguration
-