Netflix DGS Codegen + Relay Pagination 无法生成数据获取器类

问题描述 投票:0回答:2

我正在尝试为maven项目实现codegen(https://github.com/deweyjose/graphqlcodegen)以及中继分页(https://netflix.github.io/dgs/advanced/relay-pagination/)

我的 Schema.graphqls 文件是:

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! 
}

我的pom.xml已配置为:

<?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>

当我构建项目时,codegen 正在工作,并且也能够创建过滤器类和数据获取器类,但它也在生成的文件的导入中生成 EmployeeConnection ,该文件正在破坏,因为它不应该生成,而是我需要它根据 netflix dgs 文档,是这样的:

@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);
}

到目前为止,我发现在 pom 文件中,我必须在 codegen 配置中添加 , 我可以在https://netflix.github.io/dgs/advanced/relay-pagination/#configuring-code- Generation中看到相同的解决方案 但是maven怎么做呢?`

netflix-dgs
2个回答
1
投票

有了决心, 在 pom.xml 的 codegen 配置中添加了类型映射

<typeMapping>
    <EmployeeConnection>graphql.relay.SimpleListConnection&lt;Employee&gt;</EmployeeConnection>
</typeMapping>

0
投票

谢谢您的回答。 使用 typeMapping 后不起作用,是否需要为 @Connection 指令添加任何配置?

© www.soinside.com 2019 - 2024. All rights reserved.