i am trying to implement codegen for a maven project (https://github.com/deweyjose/graphqlcodegen) along with relay pagination (https://netflix.github.io/dgs/advanced/relay-pagination/)
My Schema.graphqls file is:
type Employee @connection {
id: Int!
firstName: String!
lastName: String!
}
input EmployeeFilter {
firstName: [String!]
lastName: [String!]
}
type Query {
getEmployees(): [Employee]
getEmployeesByPage( first: Int = 10 after: String filter: EmployeeFilter ): EmployeeConnection!
}
my pom.xml has been configured as:
<?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.0.6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.demo</groupId>
<artifactId>codegenPOC</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>codegenPOC</name>
<description>POC project for Spring Boot with GraphQL codegen</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.netflix.graphql.dgs</groupId>
<artifactId>graphql-dgs-platform-dependencies</artifactId>
<version>4.9.16</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.netflix.graphql.dgs</groupId>
<artifactId>graphql-dgs-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.netflix.graphql.dgs</groupId>
<artifactId>graphql-dgs-pagination</artifactId>
<version>6.0.5</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>net.sf.dozer</groupId>
<artifactId>dozer</artifactId>
<version>5.5.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.github.deweyjose</groupId>
<artifactId>graphqlcodegen-maven-plugin</artifactId>
<version>1.18</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<subPackageNameDatafetchers>graph.query</subPackageNameDatafetchers>
<subPackageNameTypes>graph.schema</subPackageNameTypes>
<schemaPaths>
<param>src/main/resources/graphql/schema/Schema.graphqls</param>
</schemaPaths>
<packageName>com.demo.codegenPOC</packageName>
<outputDir>${project.build.directory}</outputDir>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
when ever i am building the project codegen is working and is able to create filter classes and data fetcher classes too but it is generating EmployeeConnection also in the imports for the generated files which is breaking as its not supposed to generate instead i need it to be something like this as per the netflix dgs documentation:
@DgsData(parentType = "Query", field = "getEmployeesByPage")
public Connection<Employee> getEmployeesByPage(DataFetchingEnvironment dataFetchingEnvironment) {
return new SimpleListConnection<>(Collections.singletonList(new Message("This is a generated connection"))).get(dataFetchingEnvironment);
}
So far what i have found is that in the pom file in i have to add <typeMapping></typeMapping> in the codegen configurations, i can see the same solution present in the https://netflix.github.io/dgs/advanced/relay-pagination/#configuring-code-generation but how to do it for maven?`
got the resolution, added typemapping in the codegen configuration in pom.xml
<typeMapping>
<EmployeeConnection>graphql.relay.SimpleListConnection<Employee></EmployeeConnection>
</typeMapping>