Class GenerateServerCodeTask

java.lang.Object
org.gradle.api.internal.AbstractTask
org.gradle.api.DefaultTask
All Implemented Interfaces:
com.graphql_java_generator.plugin.conf.CommonConfiguration, com.graphql_java_generator.plugin.conf.GenerateCodeCommonConfiguration, com.graphql_java_generator.plugin.conf.GenerateServerCodeConfiguration, java.lang.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

public class GenerateServerCodeTask
extends GenerateCodeCommonTask
implements com.graphql_java_generator.plugin.conf.GenerateServerCodeConfiguration

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 DataFetchersDelegate interface
  • Make it implement the relevant DataFetchersDelegate interface
  • Mark it with the Component annotation

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.

  • Field Details

    • javaTypeForIDType

      public java.lang.String 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

  • Method Details

    • execute

      public void execute() throws java.io.IOException
      Throws:
      java.io.IOException
    • getJavaTypeForIDType

      @Input public final java.lang.String getJavaTypeForIDType()
      Specified by:
      getJavaTypeForIDType in interface com.graphql_java_generator.plugin.conf.GenerateServerCodeConfiguration
    • setJavaTypeForIDType

      public final void setJavaTypeForIDType​(java.lang.String javaTypeForIDType)
    • getMode

      @Input public com.graphql_java_generator.plugin.conf.PluginMode getMode()
      Specified by:
      getMode in interface com.graphql_java_generator.plugin.conf.GenerateCodeCommonConfiguration
      Overrides:
      getMode in class GenerateCodeCommonTask
    • getPackaging

      @Internal public final com.graphql_java_generator.plugin.conf.Packaging getPackaging()
      Specified by:
      getPackaging in interface com.graphql_java_generator.plugin.conf.GenerateServerCodeConfiguration
    • getQuotedScanBasePackages

      @Internal public java.lang.String getQuotedScanBasePackages()
      Specified by:
      getQuotedScanBasePackages in interface com.graphql_java_generator.plugin.conf.GenerateServerCodeConfiguration
    • getScanBasePackages

      @Input public final java.lang.String getScanBasePackages()
      Specified by:
      getScanBasePackages in interface com.graphql_java_generator.plugin.conf.GenerateServerCodeConfiguration
    • setScanBasePackages

      public final void setScanBasePackages​(java.lang.String scanBasePackages)
    • getSchemaPersonalizationFile

      @InputFile @Optional public final java.io.File getSchemaPersonalizationFile()
      Specified by:
      getSchemaPersonalizationFile in interface com.graphql_java_generator.plugin.conf.GenerateServerCodeConfiguration
    • setSchemaPersonalizationFile

      public final void setSchemaPersonalizationFile​(java.lang.String schemaPersonalizationFile)
    • isGenerateBatchLoaderEnvironment

      @Input public final boolean isGenerateBatchLoaderEnvironment()
      Specified by:
      isGenerateBatchLoaderEnvironment in interface com.graphql_java_generator.plugin.conf.GenerateServerCodeConfiguration
    • setGenerateBatchLoaderEnvironment

      public final void setGenerateBatchLoaderEnvironment​(boolean generateBatchLoaderEnvironment)
    • isGenerateJacksonAnnotations

      @Internal public boolean isGenerateJacksonAnnotations()
      Specified by:
      isGenerateJacksonAnnotations in interface com.graphql_java_generator.plugin.conf.CommonConfiguration
      Specified by:
      isGenerateJacksonAnnotations in interface com.graphql_java_generator.plugin.conf.GenerateServerCodeConfiguration
      Overrides:
      isGenerateJacksonAnnotations in class GenerateCodeCommonTask
    • isGenerateJPAAnnotation

      @Input public final boolean isGenerateJPAAnnotation()
      Specified by:
      isGenerateJPAAnnotation in interface com.graphql_java_generator.plugin.conf.GenerateServerCodeConfiguration
    • setGenerateJPAAnnotation

      public final void setGenerateJPAAnnotation​(boolean generateJPAAnnotation)
    • getExtension

      protected GenerateServerCodeExtension getExtension()
      Overrides:
      getExtension in class GenerateCodeCommonTask