Error generating classes from generateClientApi or generateClientApiV2

未关闭
#692 9 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
30/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
graphql, java
领域
api, tooling

调研方向

首先使用提供的 schema 和 pom.xml 运行 mvn clean install,然后将 ShowsProjectionRoot.java 和 ShowsGraphQLQuery.java 的构造函数与各自的 DGS 基类进行对照检查。启用 generateClientApiV2 后,生成的客户端类能够成功编译,并且报告的构造函数错误得到解决,即视为完成。

由索引模型根据 Issue 内容生成。

描述

Error generating classes from generateClientApi or generateClientApiV2.

Constructors with invalid number of arguments.

schemas:

type Query {
    shows: [Show]
}

type Show {
    title: String,
    id: String
}

I'm using graphqlcodegen-maven-plugin to generate the code. When I run mvn clean install the command generates the classes but with an error:

file: ShowsProjectionRoot.java

package com.graphql.engine.codegen.client;

import com.netflix.graphql.dgs.client.codegen.BaseSubProjectionNode;
import javax.annotation.processing.Generated;

@Generated(
    value = "com.netflix.graphql.dgs.codegen.CodeGen",
    date = "2024-05-21T18:53:11.998886400Z"
)
@com.graphql.engine.codegen.Generated
public class ShowsProjectionRoot<PARENT extends BaseSubProjectionNode<?, ?>, ROOT extends BaseSubProjectionNode<?, ?>> extends BaseSubProjectionNode<PARENT, ROOT> {
  public ShowsProjectionRoot() {
    super(null, null, java.util.Optional.of("Show")); //current  line with the error because the constructor only accepts two argument
  }

  public ShowsProjectionRoot<PARENT, ROOT> title() {
    getFields().put("title", null);
    return this;
  }

  public ShowsProjectionRoot<PARENT, ROOT> ano() {
    getFields().put("ano", null);
    return this;
  }
}

this is error:
constructor BaseSubProjectionNode in class com.netflix.graphql.dgs.client.codegen.BaseSubProjectionNode<T,R> cannot be applied to given types;

other file ShowsGraphQLQuery with error:

package com.graphql.engine.codegen.client;

import com.netflix.graphql.dgs.client.codegen.GraphQLQuery;
import java.lang.Override;
import java.lang.String;
import java.util.HashSet;
import java.util.Set;
import javax.annotation.processing.Generated;

@Generated(
    value = "com.netflix.graphql.dgs.codegen.CodeGen",
    date = "2024-05-21T18:53:11.998886400Z"
)
@com.graphql.engine.codegen.Generated
public class ShowsGraphQLQuery extends GraphQLQuery {
  public ShowsGraphQLQuery(String queryName) {
    super("query", queryName); // current  line with the error because the constructor only accepts one argument
  }

  public ShowsGraphQLQuery() {
    super("query");
  }

  @Override
  public String getOperationName() {
     return "shows";
                    
  }

  public static Builder newRequest() {
    return new Builder();
  }

  @Generated(
      value = "com.netflix.graphql.dgs.codegen.CodeGen",
      date = "2024-05-21T18:53:11.998886400Z"
  )
  @com.graphql.engine.codegen.Generated
  public static class Builder {
    private Set<String> fieldsSet = new HashSet<>();

    private String queryName;

    public ShowsGraphQLQuery build() {
      return new ShowsGraphQLQuery(queryName);                                     
    }

    public Builder queryName(String queryName) {
      this.queryName = queryName;
      return this;
    }
  }
}

ERROR: no suitable constructor found for GraphQLQuery(java.lang.String,java.lang.String)

<?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.2.5</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.graphql</groupId>
	<artifactId>engine</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>engine</name>
	<description>Demo project for Spring Boot</description>
	<properties>
		<java.version>17</java.version>
	</properties>
	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-graphql</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-devtools</artifactId>
			<scope>runtime</scope>
			<optional>true</optional>
		</dependency>
		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
			<optional>true</optional>
		</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>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-webflux</artifactId>
		</dependency>

		<!-- DGS dependencies. We don't have to specify a version here! -->
		<dependency>
			<groupId>com.netflix.graphql.dgs</groupId>
			<artifactId>graphql-dgs-spring-boot-starter</artifactId>
		</dependency>

	</dependencies>

	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>com.netflix.graphql.dgs</groupId>
				<artifactId>graphql-dgs-platform-dependencies</artifactId>
				<!-- The DGS BOM/platform dependency. This is the only place you set version of DGS -->
				<version>3.10.2</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>

	<build>
		<plugins>
			<plugin>
				<groupId>io.github.deweyjose</groupId>
				<artifactId>graphqlcodegen-maven-plugin</artifactId>
				<version>1.50</version>
				<executions>
					<execution>
						<id>dgs-codegen</id>
						<goals>
							<goal>generate</goal>
						</goals>
						<configuration>
							<schemaPaths>
								<param>src/main/resources/graphql-client</param>
							</schemaPaths>
							<packageName>com.graphql.engine.codegen</packageName>
							<addGeneratedAnnotation>true</addGeneratedAnnotation>
							<generateBoxedTypes>true</generateBoxedTypes>
							<generateDataTypes>true</generateDataTypes>
							<generateClientApiV2>true</generateClientApiV2>
							<writeToFiles>true</writeToFiles>
							<generateDocs>true</generateDocs>
						</configuration>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<groupId>org.codehaus.mojo</groupId>
				<artifactId>build-helper-maven-plugin</artifactId>
				<executions>
					<execution>
						<id>add-dgs-source</id>
						<phase>generate-sources</phase>
						<goals>
							<goal>add-source</goal>
						</goals>
						<configuration>
							<sources>
								<source>${project.build.directory}/generated-sources</source>
							</sources>
						</configuration>
					</execution>
				</executions>
			</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>

主要语言
Kotlin
星标
220
派生
123
平均合并
1 天 6 小时
30 天内合并 PR
23

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Netflix/dgs-codegen 的其他 Issue

查看 Netflix/dgs-codegen 的全部 Issue

相似的 Issue

更多 Kotlin Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。