Class GenerateServerCodeExtension

All Implemented Interfaces:
com.graphql_java_generator.plugin.conf.CommonConfiguration, com.graphql_java_generator.plugin.conf.GenerateCodeCommonConfiguration, com.graphql_java_generator.plugin.conf.GenerateServerCodeConfiguration
Direct Known Subclasses:
GraphQLExtension

public class GenerateServerCodeExtension extends GenerateCodeCommonExtension implements com.graphql_java_generator.plugin.conf.GenerateServerCodeConfiguration
  • Field Details

    • generateBatchMappingDataFetchers

      public boolean generateBatchMappingDataFetchers

      If this parameter is set to true, the spring GraphQL controller methods will be annotated with the @BatchMapping (instead of the @SchemaMapping). This allows to manage the of the N+1 select problem: so this allows much better performances, by highly diminishing the number of executed requests (avoid to execute several times the same "sub-query")

      When setting this parameter to true, the main changes are:

      • The @BatchMapping annotation may be applied to all data fetchers without argument(s) that return either a List, a Type, an Interface or an Union.
      • The return type must be defined in the controller: it may not be `Object`, as spring-graphql builds the proper BatchLoader while loading the controllers, when the server starts. The return type for this method is managed by the batchMappingMethodReturnType plugin parameter
      • DataLoader is managed transparently by spring (instead of having to declare it in the generated controller, and having it as a parameter in the generated data fetchers)
      • The batch mapping is generalized on all data fetchers
      • The DataFetchersDelegate method's signature changes
      • The generateBatchLoaderEnvironment, generateDataFetcherForEveryFieldsWithArguments and generateDataLoaderForLists plugin parameters are ignored

      A typical method signature for a data fetcher would be as below, where the return type is controller by the batchMappingMethodReturnType plugin parameter :

       public Flux topics(//
                      BatchLoaderEnvironment batchLoaderEnvironment, //
                      GraphQLContext graphQLContext, //
                      List boards);
       

      Please note that the @BatchMapping annotation is a shortcut to avoid boilerplate code, for the most common cases. See this discussion for more information on this. For most complex cases, the use of a DataLoader is recommended by the spring-graphql case. And in these cases, the plugin will generate a method with the @SchemaMapping annotation

    • generateDataFetcherForEveryFieldsWithArguments

      public boolean generateDataFetcherForEveryFieldsWithArguments

      (only for server mode, since 2.5) Defines if a data fetcher is needed for every GraphQL field that has input argument, and add them in the generated POJOs. This allows a better compatibility with spring-graphql, and an easy access to the field's parameters.

      With this argument to false, the data fetchers are generated only for field which type is a type (not a scalar or an enum), and for the query, mutation and subscription types.

      With this argument to true, the data fetchers are generated for all GraphQL fields which type is a type (not a scalar or an enum) or that has one or arguments

      This parameter is available since version 2.5. Its default value is false in 2.x versions for backward compatibility with existing implementations based on the plugin. But the recommended value is true.

    • ignoredSpringMappings

      public String ignoredSpringMappings

      This parameter marks a list of GraphQL mappings as ignored, so that they are not generated by the plugin. These ignored mappings can then be defined by the specific implementation.

      The other way to it is to create a spring GraphQL Controller, that overrides the controller generated by the plugin. But this may lead to this error: Ambiguous mapping. Cannot map 'xxxController' method [...] to 'Type.field': there is already 'yyy' bean method [...] mapped.

      The parameter may contain:

      • The '*' character: this would mark all controllers and DataFetchersDeleagate to be ignored. That is: none would be generated, and it's up to the specific implementation to manage them. In this mode, you still benefit of the POJO generation, the type wiring, the custom scalars mapping...
      • A list of:
        • GraphQL type name: The full controller class for this type is ignored, and won't be generated
        • GraphQL type's field name: The method in the controller of this type, for this field, is ignored, and won't be generated. The field must be written like this: {type name}.{field name}

      The accepted separators for the values are: comma, space, carriage return, end of line, space, tabulation. At least one separator must exist between two values in the list. Here is a sample:

                Type1, Type2.field1
                      Type3
                      Type4.field2
                
       

      For field mapping, there must be no separator other than '.' between the type name and the field name. For instance, the following type declaration are invalid: 'type .field', 'type. field'

      To implement the ignored mappings, you'll have to follow the [spring-graphql documentation](https://docs.spring.io/spring-graphql/reference/controllers.html).

    • javaTypeForIDType

      public 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

    • GenerateServerCodeExtension

      public GenerateServerCodeExtension(org.gradle.api.file.ProjectLayout projectLayout, com.graphql_java_generator.plugin.conf.Packaging packaging)
  • Method Details

    • isGenerateBatchLoaderEnvironment

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

      public void setGenerateBatchLoaderEnvironment(boolean generateBatchLoaderEnvironment)
    • isGenerateBatchMappingDataFetchers

      public boolean isGenerateBatchMappingDataFetchers()
      Specified by:
      isGenerateBatchMappingDataFetchers in interface com.graphql_java_generator.plugin.conf.GenerateServerCodeConfiguration
    • setGenerateBatchMappingDataFetchers

      public void setGenerateBatchMappingDataFetchers(boolean generateBatchMappingDataFetchers)
    • isGenerateDataFetcherForEveryFieldsWithArguments

      public boolean isGenerateDataFetcherForEveryFieldsWithArguments()
      Specified by:
      isGenerateDataFetcherForEveryFieldsWithArguments in interface com.graphql_java_generator.plugin.conf.GenerateServerCodeConfiguration
    • setGenerateDataFetcherForEveryFieldsWithArguments

      public void setGenerateDataFetcherForEveryFieldsWithArguments(boolean generateDataFetcherForEveryFieldsWithArguments)
    • isGenerateJPAAnnotation

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

      public void setGenerateJPAAnnotation(boolean generateJPAAnnotation)
    • isGenerateDataLoaderForLists

      public boolean isGenerateDataLoaderForLists()
      Specified by:
      isGenerateDataLoaderForLists in interface com.graphql_java_generator.plugin.conf.GenerateServerCodeConfiguration
    • setGenerateDataLoaderForLists

      public final void setGenerateDataLoaderForLists(boolean generateDataLoaderForLists)
    • getBatchMappingDataFetcherReturnType

      public com.graphql_java_generator.plugin.conf.BatchMappingDataFetcherReturnType getBatchMappingDataFetcherReturnType()
      Specified by:
      getBatchMappingDataFetcherReturnType in interface com.graphql_java_generator.plugin.conf.GenerateServerCodeConfiguration
    • setBatchMappingDataFetcherReturnType

      public void setBatchMappingDataFetcherReturnType(com.graphql_java_generator.plugin.conf.BatchMappingDataFetcherReturnType batchMappingDataFetcherReturnType)
    • getIgnoredSpringMappings

      public String getIgnoredSpringMappings()
      Specified by:
      getIgnoredSpringMappings in interface com.graphql_java_generator.plugin.conf.GenerateServerCodeConfiguration
    • setIgnoredSpringMappings

      public final void setIgnoredSpringMappings(String ignoredSpringMappings)
    • getJavaTypeForIDType

      public String getJavaTypeForIDType()
      Specified by:
      getJavaTypeForIDType in interface com.graphql_java_generator.plugin.conf.GenerateServerCodeConfiguration
    • setJavaTypeForIDType

      public void setJavaTypeForIDType(String javaTypeForIDType)
    • getMode

      public com.graphql_java_generator.plugin.conf.PluginMode getMode()
      The mode is forced to PluginMode.server
      Specified by:
      getMode in interface com.graphql_java_generator.plugin.conf.GenerateCodeCommonConfiguration
      Overrides:
      getMode in class GenerateCodeCommonExtension
    • getPackaging

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

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

      public String getScanBasePackages()
      Specified by:
      getScanBasePackages in interface com.graphql_java_generator.plugin.conf.GenerateServerCodeConfiguration
    • setScanBasePackages

      public void setScanBasePackages(String scanBasePackages)