Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dpalmmna opened this issue Apr 19, 2023 · 3 comments
Closed

Comments

@dpalmmna
Copy link
Contributor

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
Copy link
Collaborator

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
Copy link
Contributor Author

dpalmmna commented Apr 20, 2023

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

@etienne-sf
Copy link
Collaborator

Hello,

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants