No Projection is generated for Mutations only ProjectionRoot
I'm currently having issues with testing out queries in integration tests using the codgen.
I can't figure out why there is no getTemporaryUploadUrlProjection class generated. For every other type there is a <TYPENAME>Projectiongenerated. I can't figure out what is the reason for the Projection class not being generated and would be grateful for some guidance.
These are the following classes which got generated:
- GetTemporaryUploadUrlGraphQLQuery
- GetTemporaryUploadUrlProjectionRoot
However when I try the following code:
final GetTemporaryUploadUrlProjectionRoot<?, ?> projection =
new GetTemporaryUploadUrlProjectionRoot<>()
.url();
new GraphQLQueryRequest(
GetTemporaryUploadUrlGraphQLQuery.newRequest().build(),
projection
).serialize()
I get the following error null cannot be cast to non-null type com.netflix.graphql.dgs.client.codegen.BaseProjectionNode
Which can be traced back into the serialize method of com.netflix.graphql.dgs.client.codegen.GraphQLQueryRequest which does a check and fails on the error message if root is null. Root is null for all ProjectionRoot classes.
Decompiled kotlin to java
if (this.projection instanceof BaseSubProjectionNode) {
ProjectionSerializer var10001 = this.projectionSerializer;
Object var9 = ((BaseSubProjectionNode)this.projection).root();
if (var9 == null) {
throw new NullPointerException("null cannot be cast to non-null type com.netflix.graphql.dgs.client.codegen.BaseProjectionNode");
}
The ProjectionRoot class signature
public class GetTemporaryUploadUrlProjectionRoot<PARENT extends BaseSubProjectionNode<?, ?>, ROOT extends BaseSubProjectionNode<?, ?>> extends BaseSubProjectionNode<PARENT, ROOT> {
public GetTemporaryUploadUrlProjectionRoot() {
super(null, null, java.util.Optional.of("TemporaryUploadUrlResponse"));
}
Relevant Schema
type Mutation {
getTemporaryUploadUrl: TemporaryUploadUrlResponse
}
type TemporaryUploadUrlResponse {
url: String!
}
My pom.xml (running coretto java 21)
<build>
<plugins>
<plugin>
<groupId>io.github.deweyjose</groupId>
<artifactId>graphqlcodegen-maven-plugin</artifactId>
<version>1.61.5</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaPaths>
<param>src/main/resources/schema/mutation.graphqls</param>
<param>src/main/resources/schema/query.graphqls</param>
<param>src/main/resources/schema/scalars.graphqls</param>
<param>src/main/resources/schema/types.graphqls</param>
</schemaPaths>
<packageName>com.randomorg.api.generated</packageName>
<generateClientApiV2>true</generateClientApiV2>
<skipEntityQueries>false</skipEntityQueries>
<addGeneratedAnnotation>true</addGeneratedAnnotation>
<typeMapping>
<BigDecimal>java.math.BigDecimal</BigDecimal>
<PositiveInt>java.lang.Integer</PositiveInt>
<NonNegativeInt>graphql.scalars.numeric.NonNegativeIntScalar</NonNegativeInt>
</typeMapping>
</configuration>
</plugin>
I tried to move the code into query but the Projectionclass is still not being generated.
Hi @jamesHau
Could you take a look at the companion example repo? It has an example of a client query construction for both queries and parameterized mutations.
For example - here's the code I have to call the createShow mutation.
Can you share what version of the following you're using?
<dependency>
<groupId>com.netflix.graphql.dgs.codegen</groupId>
<artifactId>graphql-dgs-codegen-shared-core</artifactId>
</dependency>