Class AbstractGenerateServerCodeMojo

    • Field Detail

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

        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.

        Default value is false

      • javaTypeForIDType

        @Parameter(property="com.graphql_java_generator.mavenplugin.javaTypeForIDType",
                   defaultValue="java.util.UUID")
        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 Detail

      • AbstractGenerateServerCodeMojo

        protected AbstractGenerateServerCodeMojo​(java.lang.Class<?> springConfigurationClass)