dgs-codegen
dgs-codegen copied to clipboard
bug: Kotlin Codegen fails to generate Code when field name `package` is present
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
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
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
Closing the issue in the framework since it's now in dgs-codegen
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
}
fyi. @mbossenbroek
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?
@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 did you find any workaround for this?
@mbossenbroek - could you take another look when you get a chance?
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 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.
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: @.***>