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

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

Open
JLLeitschuh opened this issue Dec 31, 2023 · 12 comments
Labels
bug Something isn't working

Comments

@JLLeitschuh
Copy link

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 JLLeitschuh added the bug Something isn't working label Dec 31, 2023
@srinivasankavitha
Copy link
Contributor

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

@JLLeitschuh
Copy link
Author

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

@srinivasankavitha srinivasankavitha transferred this issue from Netflix/dgs-framework Jan 8, 2024
@srinivasankavitha
Copy link
Contributor

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

@srinivasankavitha
Copy link
Contributor

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
Copy link
Contributor

fyi. @mbossenbroek

@mbossenbroek
Copy link
Contributor

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?

@zlishaojiez
Copy link

zlishaojiez commented May 28, 2024

@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.

@jonathanwiemers
Copy link

@zlishaojiez did you find any workaround for this?

@srinivasankavitha
Copy link
Contributor

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

@mbossenbroek
Copy link
Contributor

My apologies - I saw the "with Java" in the last comment & thought it was for the other stuff. This PR should fix: #700

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

@ryan-rushton
Copy link

ryan-rushton commented Aug 29, 2024

@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.

@mbossenbroek
Copy link
Contributor

mbossenbroek commented Aug 29, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants