Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No Projection is generated for Mutations only ProjectionRoot #184

Open
jamesHau opened this issue Sep 29, 2024 · 1 comment
Open

No Projection is generated for Mutations only ProjectionRoot #184

jamesHau opened this issue Sep 29, 2024 · 1 comment

Comments

@jamesHau
Copy link

jamesHau commented Sep 29, 2024

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>
@jamesHau
Copy link
Author

I tried to move the code into query but the Projectionclass is still not being generated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant