dgs-codegen icon indicating copy to clipboard operation
dgs-codegen copied to clipboard

bug: Kotlin Codegen fails to generate Code when field name `package` is present

Open JLLeitschuh opened this issue 1 year ago • 12 comments

Expected behavior

I was attempting to generate a client for the GitHub GraphQL API: https://docs.github.com/en/graphql/overview/public-schema

Unfortunately, it has a few fields name package and one type called Package thus causing an exception to get thrown when the code is generated

Actual behavior

Currently, the Gradle build fails with an error that package is an invalid name

Steps to reproduce

Note: A test case would be highly appreciated, but we understand that's not always possible

JLLeitschuh avatar Dec 31 '23 04:12 JLLeitschuh

Can you also please share your codegen settings? Also, it would be really helpful if you can move this issue to the our dgs-codegen repo: https://github.com/Netflix/dgs-codegen/issues

srinivasankavitha avatar Jan 05 '24 19:01 srinivasankavitha

Any maintainer who is a part of both projects shoul (theoretically) be able to move this issue between repos.

Regarding codegen config, I was generating code for Kotlin with the client code, with basically all other settings in default mode

JLLeitschuh avatar Jan 08 '24 14:01 JLLeitschuh

Closing the issue in the framework since it's now in dgs-codegen

srinivasankavitha avatar Jan 08 '24 22:01 srinivasankavitha

Are you using the following settings?

generateClientApi = true,
generateKotlinNullableClasses = true,
generateKotlinClosureProjections = true

I tried it with a sample schema like this and it compiles fine:

            type Query {
                people: [Person]
            }
            
            type Person {
                package: String
                interface: String
            }

srinivasankavitha avatar Jan 08 '24 23:01 srinivasankavitha

fyi. @mbossenbroek

srinivasankavitha avatar Jan 08 '24 23:01 srinivasankavitha

Confirmed this works with the kotlin2 stuff as well, and checked for a type named Package. There were a few bugs related to escaping that were fixed recently - what version are you using @JLLeitschuh ?

If that's not the case, could you provide a minimal GQL schema that repros?

mbossenbroek avatar Jan 08 '24 23:01 mbossenbroek

@srinivasankavitha @mbossenbroek I also got the "Cause: not a valid name: package" to generate a client for the GitHub GraphQL API: https://docs.github.com/en/graphql/overview/public-schema with Java (Springboot project)

with the code gen 6.2.1

And there are some schemas as

`type Query { people: [Person] }

type Person { info( package: String ): String interface: String }`

It will cause the exception.

zlishaojiez avatar May 28 '24 16:05 zlishaojiez

@zlishaojiez did you find any workaround for this?

jonathanwiemers avatar Jun 10 '24 15:06 jonathanwiemers

@mbossenbroek - could you take another look when you get a chance?

srinivasankavitha avatar Jun 10 '24 16:06 srinivasankavitha

My apologies - I saw the "with Java" in the last comment & thought it was for the other stuff. This PR should fix: https://github.com/Netflix/dgs-codegen/pull/700

Also I added your repro case as a test case in there for it too.

mbossenbroek avatar Jun 10 '24 17:06 mbossenbroek

@mbossenbroek is the fix expected to be released core or the plugin itself?

I am also getting this trying to generate a java client using the github schema same as @zlishaojiez.

I am using the maven plugin

<groupId>io.github.deweyjose</groupId>
<artifactId>graphqlcodegen-maven-plugin</artifactId>
<version>1.61.5</version>

which is using core version 6.2.4.

If it is an in plugin fix, I can take this over there.

ryan-rushton avatar Aug 29 '24 01:08 ryan-rushton

This fix was released a while ago. I'm not familiar with the maven plugin; this was just a fix in the core codegen logic.

On Wed, Aug 28, 2024 at 6:19 PM Ryan Rushton @.***> wrote:

@mbossenbroek https://github.com/mbossenbroek is the fix expected to be released?

I am also getting this trying to generate a java client using the github schema same as @zlishaojiez https://github.com/zlishaojiez.

I am using the maven plugin

<groupId>io.github.deweyjose</groupId> <artifactId>graphqlcodegen-maven-plugin</artifactId> 1.61.5

which is using https://github.com/deweyjose/graphqlcodegen/blob/main/pom.xml#L38 version 6.2.4.

— Reply to this email directly, view it on GitHub https://github.com/Netflix/dgs-codegen/issues/641#issuecomment-2316536005, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABPDI34E6BPTVVXZ7AXS5ODZTZZLLAVCNFSM6AAAAABBSEU276VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMJWGUZTMMBQGU . You are receiving this because you were mentioned.Message ID: @.***>

mbossenbroek avatar Aug 29 '24 15:08 mbossenbroek