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

Client-side codegen fails if there are multiple queries with same name #106

Closed
kobylynskyi opened this issue Apr 25, 2020 · 8 comments · Fixed by #120
Closed

Client-side codegen fails if there are multiple queries with same name #106

kobylynskyi opened this issue Apr 25, 2020 · 8 comments · Fixed by #120
Assignees
Labels
bug Something isn't working
Milestone

Comments

@kobylynskyi
Copy link
Owner

Issue Description

Code generation fails for the following schema:

    smthng(param1: String!): ResponseType
    smthng(param1: String!, param2: String!): ResponseType

config:

graphqlCodegen {
    outputDir = new File("$buildDir/generated-client")
    generateRequests = true
    generateApis = false
}

Output:

java.nio.file.FileAlreadyExistsException: File already exists: .../build/generated-client/SmthngQueryRequest.java

@ghost
Copy link

ghost commented May 5, 2020

Hi @kobylynskyi, will this be part of version 1.7.3 or later? I do see this issue up to 1.7.2. Thank you!

@kobylynskyi
Copy link
Owner Author

Hi @jyjyj
The fix was a part of 1.7.0.
What exact issue do you see? Please provide sample schema.
Thanks!

@ghost
Copy link

ghost commented May 5, 2020

Hi @kobylynskyi, I see the errors that I previously mentioned in #141. In particular, my schema looks like
assignUsersToTask(taskId: String!, userId: String!, workerIdList: [String!]!): Boolean! assignUsersToTask(taskId: String!, userId: String!, workerIdList: AddRemoveWorkerList!): Boolean!

After renaming one of them, there were no errors. AddRemoveWorkerList is a custom defined input looking like
input AddRemoveWorkerList { add: [String!]! remove: [String!]! }

Thanks!

@kobylynskyi
Copy link
Owner Author

kobylynskyi commented May 5, 2020

That's an expected error.
Because you have two mutations with the same name and same parameter names.

@jyjyj How do you suggest to name generated classes?

@ghost
Copy link

ghost commented May 5, 2020

@kobylynskyi, my bad for missing that. Thought I did rename them differently but I guess I only did so for the parameter type. Correct me if I'm wrong, but Java is not able to differentiate multiple functions with the same signature except of different parameter types? Either way, thank you for pointing it out!

@kobylynskyi
Copy link
Owner Author

@jyjyj Well, Java allows overloading methods: with the same name and same parameter names (but parameters should have a different type).
The thing is that graphql-java-codegen creates a separate class for each Query/Mutation/Subscription based on the name of GraphQL query/mutation/subscription.
If that name is used twice, then we are taking into account parameter names while generating a class. And if the pair [QueryName+ParameterNames] occurs twice within the same type, then it is an error.
I hope it helps in some way.

@ghost
Copy link

ghost commented May 6, 2020

Hi @kobylynskyi, if method overloading is allowed for the same name and same parameter type, and if 2 resolvers were created with the same name, would they not just be generated in the same interface as 2 different methods?

@kobylynskyi
Copy link
Owner Author

@jyjyj
Actually these methods are being properly generated in Query.java, Mutation.java, etc.
But the problem comes when generating a separate class for each query/mutation.

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

Successfully merging a pull request may close this issue.

1 participant