Interface GenerateServerCodeConfiguration

All Superinterfaces:
CommonConfiguration, GenerateCodeCommonConfiguration
All Known Subinterfaces:
GeneratePojoConfiguration, GraphQLConfiguration

public interface GenerateServerCodeConfiguration extends GenerateCodeCommonConfiguration
This class contains all parameters for the generateServerCode goal/task.
Author:
etienne-sf
  • Field Details

  • Method Details

    • getBatchMappingDataFetcherReturnType

      BatchMappingDataFetcherReturnType getBatchMappingDataFetcherReturnType()

      This parameter is used only when generateBatchMappingDataFetchers is set to true. It determines the return type of the data fetchers, as defined in the spring-graphql documentation.

      The allowed values are (where K is the key type, that is: the parent object, and V is the value to be loaded in batch):

      Mono<Map<K,V>>
      Value Return type MONO_MAP MAP Map<K,V> FLUX> Flux<V> COLLECTION Collection<V>

      The default value is Flux<V>

      For an easier use of this parameter, the comment of the generated data fetchers details the exact expected type.

    • getPackaging

      Packaging getPackaging()
      (only for server mode) The packaging is the kind of artefact generated by the project. Typically: jar (for a standard Java application) or war (for a webapp)
    • getIgnoredSpringMappings

      String getIgnoredSpringMappings()

      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).

    • getJavaTypeForIDType

      String getJavaTypeForIDType()

      (only for server mode) 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.

      Returns:
    • getScanBasePackages

      String getScanBasePackages()

      (only for server mode) A comma separated list of package names, without double quotes, that will also be parsed by Spring, to discover Spring beans, Spring repositories and JPA entities when the server starts. You should use this parameter only for packages that are not subpackage of the package defined in the _packageName_ parameter and not subpackage of com.graphql_java_generator

      This allows for instance, to set packageName to your.app.package.graphql, and to define your Spring beans, like the DataFetcherDelegates or your Spring data repositories in any other folder, by setting for instance scanBasePackages to your.app.package.impl, your.app.package.graphql, or just your.app.package

    • getQuotedScanBasePackages

      default String getQuotedScanBasePackages()
      (only for server mode) Transform the list of package names returned by getScanBasePackages() by a list of package names, surrounded by double quotes, as it can be used in the Spring scanBasePackages property of the &SpringBootApplication Spring annotation.
      Returns:
      A string that can be added to the scanBasePackages property of &SpringBootApplication, that is: an empty String, or a list of quoted package names starting with a comma (e.g.: ", \"my.package\", \"my.other.package\"")
    • isGenerateBatchLoaderEnvironment

      boolean isGenerateBatchLoaderEnvironment()

      (only for server mode) Indicates if the plugin should generate add the BatchLoaderEnvironment parameter 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 the DataLoader.load(Object, Object) method.

      This parameter is forced to true when the generateBatchMappingDataFetchers parameter is set to true.

      * 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 Map with all the needed values, instead of just the parameter value.

      The default value changed since 2.0 version: it is false in 1.x version, and true since the 2.0 version

    • isGenerateBatchMappingDataFetchers

      boolean isGenerateBatchMappingDataFetchers()

      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

    • isGenerateDataFetcherForEveryFieldsWithArguments

      boolean isGenerateDataFetcherForEveryFieldsWithArguments()

      (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.

      This parameter is forced to true when the generateBatchMappingDataFetchers parameter is set to true.

      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.

      Returns:
    • isGenerateDataLoaderForLists

      boolean isGenerateDataLoaderForLists()

      (only for server mode) Defines how the methods in the data fetchers delegates are generated. The detailed information is available in the Wiki server page

      This parameter is forced to true when the generateBatchMappingDataFetchers parameter is set to true.

      When generateDataLoaderForLists is false (default mode), the data loaders are used only for fields that don't return a list. In other words, for fields which type is a sub-object with an id, two methods are generated: one which returns a CompletableFuture, and one which returns a none CompletableFuture result (that is used by the generated code only if no data loader is available).

      When generateDataLoaderForLists is true, the above behavior is extended to fields that are a list.

      Note: if set to true, this plugin parameter make the use of data loader mandatory for every field which type is a list of GraphQL objects, which have an id. This may not be suitable, for instance when your data is stored in a relational database, where you would need a first query to retrieve the ids and push them into the data loader, then another one to retrieve the associated values. If you want to use data loader for only some of particular fields, you should consider using the generateDataLoaderForLists. You'll find more information on the Wiki server page.

      This parameter is available since version 1.18.4

      Returns:
    • isGenerateJacksonAnnotations

      default boolean isGenerateJacksonAnnotations()
      This method is used only in GeneratePojoConfiguration.

      In server mode, the Jackson annotations are always generated

      Specified by:
      isGenerateJacksonAnnotations in interface CommonConfiguration
      Returns:
      The GeneratePojoConfiguration implementation of this method always returns true
      See Also:
    • isGenerateJPAAnnotation

      boolean isGenerateJPAAnnotation()

      (only for server mode) Indicates whether the plugin should generate the JPA annotations, for generated objects.

      Default value is false

    • logConfiguration

      default void logConfiguration()
      Logs all the configuration parameters (only when in the debug level)
      Specified by:
      logConfiguration in interface CommonConfiguration
      Specified by:
      logConfiguration in interface GenerateCodeCommonConfiguration
    • logGenerateServerCodeConfiguration

      default void logGenerateServerCodeConfiguration()
      Logs all the configuration parameters for the generateServerCode task/goal (only when in the debug level)