javamavengraphql-java

GraphQL maven plugin java generator giving compile time error


Trying to generate server side code from graphQL schema using following plugin but generated code is having a compile time error "package com.graphql_java_generator.server.util does not exist". There is no jar added with this package.

https://github.com/graphql-java-generator/GraphQL-Forum-Maven-Tutorial-server

Here is my POM.xml created as per above tutorial

    <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.1.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>GraphqlCodeGen</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>GraphqlCodeGen</name>
    <description>GraphqlCodeGen</description>
    <properties>
        <java.version>17</java.version>
        <graphql-maven-plugin.version>2.3.1</graphql-maven-plugin.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-graphql</artifactId>
        </dependency>
        <dependency>
            <groupId>com.graphql-java-generator</groupId>
            <artifactId>graphql-java-server-runtime</artifactId>
            <version>${graphql-maven-plugin.version}</version>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webflux</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.graphql</groupId>
            <artifactId>spring-graphql-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>com.graphql-java-generator</groupId>
                <artifactId>graphql-maven-plugin</artifactId>
                <version>${graphql-maven-plugin.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generateServerCode</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <!-- Let's configure the GraphQL Gradle Plugin: -->
                    <!-- All available parameters are described here: -->
                    <!-- https://graphql-maven-plugin-project.graphql-java-generator.com/graphql-maven-plugin/generateServerCode-mojo.html -->
                    <packageName>org.forum.server.graphql</packageName>
                    <scanBasePackages>org.forum.server.impl, org.forum.server.jpa</scanBasePackages>
                    <customScalars>
                        <customScalar>
                            <graphQLTypeName>Date</graphQLTypeName>
                            <javaType>java.util.Date</javaType>
                            <graphQLScalarTypeStaticField>com.graphql_java_generator.customscalars.GraphQLScalarTypeDate.Date
                            </graphQLScalarTypeStaticField>
                        </customScalar>
                    </customScalars>
                    <!-- The parameters below change the 1.x default behavior. They are set to respect the behavior of the future 2.x versions -->
                    <copyRuntimeSources>false</copyRuntimeSources>
                    <generateBatchLoaderEnvironment>true</generateBatchLoaderEnvironment>
                    <separateUtilityClasses>true</separateUtilityClasses>
                    <skipGenerationIfSchemaHasNotChanged>true</skipGenerationIfSchemaHasNotChanged>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

https://stackoverflow.com/users/5056068/etienne-sf tagging you for your kind attention


Solution

  • The issue is due to <type>pom</type>

    This is due to an error in the doc: this changed in an early version of the plugin, but this change has not be reported into the doc.

    The graphql-java-server-runtime dependency should be written this way:

            <dependency>
             <groupId>com.graphql-java-generator</groupId>
                <artifactId>graphql-java-server-runtime</artifactId>
                <version>${graphql-maven-plugin.version}</version>
            </dependency>
    

    The doc is now corrected.

    Etienne