graphql-java-generator / graphql-maven-plugin-project

graphql-maven-plugin is a Maven Plugin for GraphQL, based on graphql-java. It accelerates the development for both the client and the server, by generating the Java code. It allows a quicker development when in contract-first approach, by avoiding to code the boilerplate code.
https://graphql-maven-plugin-project.graphql-java-generator.com
MIT License
118 stars 47 forks source link

Unable to use custom scalars upgrade from 1.18.9 to 1.18.10 (Or 2.0RC1) #184

Closed dpalmmna closed 1 year ago

dpalmmna commented 1 year ago

While attempting to upgrade from 1.18.9 to 1.18.10 the generation now fails on custom scalars.

The code that causes errors is

public String getPackageName(String classFullNameParam)

The method exists with message Could not find the package for the class 'org.locationtech.jts.geom.Geometry', due to: org.locationtech.jts.geom.Geometry.

The pom.xml configuration is :

            <plugin>
                <groupId>com.graphql-java-generator</groupId>
                <artifactId>graphql-maven-plugin</artifactId>
                <version>1.18.10</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generateClientCode</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <packageName>fr.cs.maps.mission.mus.database</packageName>
                    <customScalars>
                        <customScalar>
                            <graphQLTypeName>timestamp</graphQLTypeName>
                            <javaType>java.time.LocalDateTime</javaType>
                            <graphQLScalarTypeStaticField>
                                fr.cs.maps.database.customscalars.MAPSGraphQLScalarType.LocalDateTime
                            </graphQLScalarTypeStaticField>
                        </customScalar>
                        <customScalar>
                            <graphQLTypeName>geometry</graphQLTypeName>
                            <javaType>org.locationtech.jts.geom.Geometry</javaType>
                            <graphQLScalarTypeStaticField>
                                fr.cs.maps.database.customscalars.MAPSGraphQLScalarType.Geometry
                            </graphQLScalarTypeStaticField>
                        </customScalar>
                        <customScalar>
                            <graphQLTypeName>geography</graphQLTypeName>
                            <javaType>org.locationtech.jts.geom.Geometry</javaType>
                            <graphQLScalarTypeStaticField>
                                fr.cs.maps.database.customscalars.MAPSGraphQLScalarType.Geography
                            </graphQLScalarTypeStaticField>
                        </customScalar>
                        <customScalar>
                            <graphQLTypeName>float8</graphQLTypeName>
                            <javaType>java.lang.Double</javaType>
                            <graphQLScalarTypeStaticField>graphql.Scalars.GraphQLFloat</graphQLScalarTypeStaticField>
                        </customScalar>
                        <customScalar>
                            <graphQLTypeName>bytea</graphQLTypeName>
                            <javaType>java.lang.String</javaType>
                            <graphQLScalarTypeStaticField>graphql.Scalars.GraphQLString</graphQLScalarTypeStaticField>
                        </customScalar>
                    </customScalars>
                    <templates>
                        <JACKSON_DESERIALIZERS>
                            target/generated-templates/templates/customtemplates/client_jackson_deserializers.vm.java
                        </JACKSON_DESERIALIZERS>
                    </templates>
                    <!-- The parameters below change the 1.x default behavior to respect the future 2.x behavior -->
                    <copyRuntimeSources>false</copyRuntimeSources>
                    <generateDeprecatedRequestResponse>false</generateDeprecatedRequestResponse>
                    <separateUtilityClasses>true</separateUtilityClasses>
                    <skipGenerationIfSchemaHasNotChanged>false</skipGenerationIfSchemaHasNotChanged>
                </configuration>
            </plugin>
<dependencies>

        <dependency>
            <groupId>fr.cs.maps</groupId>
            <artifactId>maps-framework-commons-api</artifactId>
        </dependency>
        <dependency>
            <groupId>fr.cs.maps</groupId>
            <artifactId>maps-framework-commons-database</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.15</version>
        </dependency>

        <!-- Dependencies for GraphQL GeoJson -->
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-geojsondatastore</artifactId>
        </dependency>
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-geojson</artifactId>
        </dependency>
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-shapefile</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

How to allow the generation with this new code, using types from external libraries?

etienne-sf commented 1 year ago

Hello,

I'm surprised and annoyed that, with all the integration tests I have, this bug is possible.

I could repeat this issue with the pom you provided. And yes, the dependencies for each custom scalar is mandatory. A workaround is to add the dependency to the plugin, like this:

            <plugin>
                <groupId>com.graphql-java-generator</groupId>
                <artifactId>graphql-maven-plugin</artifactId>
                <version>1.18.10</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generateClientCode</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <packageName>fr.cs.maps.mission.mus.database</packageName>
                    <customScalars>
                        <customScalar>
                            <graphQLTypeName>timestamp</graphQLTypeName>
                            <javaType>java.time.LocalDateTime</javaType>
                            <graphQLScalarTypeStaticField>
                                fr.cs.maps.database.customscalars.MAPSGraphQLScalarType.LocalDateTime
                            </graphQLScalarTypeStaticField>
                        </customScalar>
                        <customScalar>
                            <graphQLTypeName>geometry</graphQLTypeName>
                            <javaType>org.locationtech.jts.geom.Geometry</javaType>
                            <graphQLScalarTypeStaticField>
                                fr.cs.maps.database.customscalars.MAPSGraphQLScalarType.Geometry
                            </graphQLScalarTypeStaticField>
                        </customScalar>
                        <customScalar>
                            <graphQLTypeName>geography</graphQLTypeName>
                            <javaType>org.locationtech.jts.geom.Geometry</javaType>
                            <graphQLScalarTypeStaticField>
                                fr.cs.maps.database.customscalars.MAPSGraphQLScalarType.Geography
                            </graphQLScalarTypeStaticField>
                        </customScalar>
                        <customScalar>
                            <graphQLTypeName>float8</graphQLTypeName>
                            <javaType>java.lang.Double</javaType>
                            <graphQLScalarTypeStaticField>graphql.Scalars.GraphQLFloat</graphQLScalarTypeStaticField>
                        </customScalar>
                        <customScalar>
                            <graphQLTypeName>bytea</graphQLTypeName>
                            <javaType>java.lang.String</javaType>
                            <graphQLScalarTypeStaticField>graphql.Scalars.GraphQLString</graphQLScalarTypeStaticField>
                        </customScalar>
                    </customScalars>
                    <!-- The parameters below change the 1.x default behavior to respect the future 2.x behavior -->
                    <copyRuntimeSources>false</copyRuntimeSources>
                    <generateDeprecatedRequestResponse>false</generateDeprecatedRequestResponse>
                    <separateUtilityClasses>true</separateUtilityClasses>
                    <skipGenerationIfSchemaHasNotChanged>false</skipGenerationIfSchemaHasNotChanged>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.locationtech.jts</groupId>
                        <artifactId>jts-core</artifactId>
                        <version>1.15.1</version>
                    </dependency>
                </dependencies>
            </plugin>

I didn't check all the scalars you've defined, so perhaps other dependencies must be added for your all project to work.

It will be solved in a next version. Etienne

dpalmmna commented 1 year ago

Adding the dependency worked. Thxs. This is an acceptable solution.

etienne-sf commented 1 year ago

Hello,

The correction for this issue has been released the 2.3 version. I'll see to add it into the 1.x version