-
Notifications
You must be signed in to change notification settings - Fork 737
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
[v1.0.0 alpha] PascalCase GraphQL operation names generate code that doesn't compile #2167
Comments
Thanks so much for pointing this out! We'll get this fixed for an upcoming Alpha version! |
@klanchman I'd like your opinion on how we should handle this. It's a very easy fix to just make all the generated field names lowercased. I like this because it enforces Swift naming conventions, and it really simplifies this problem. It basically would do what you suggest in your workaround without you needed to alias the fields. So it would generate this: public struct Data: AniListAPI.SelectionSet {
// ...snip
public static var selections: [Selection] { [
.field("Staff", Staff?.self),
] }
public var staff: Staff? { data["Staff"] }
/// Staff
public struct Staff: AniListAPI.SelectionSet {
// ...snip
}
} Do you feel like it is valuable or necessary that we maintain the PascalCase 1:1 as is on the schema? That would require us to namespace variables, which would cause more complexity in the code generation logic, hurting performance, and generating uglier type names. This would mean that ALL nested entity fields that are PascalCased would have to be name spaced also. In your example this isn't too bad, but imagine if public struct Data: AniListAPI.SelectionSet {
// ...snip
public static var selections: [Selection] { [
.field("Staff", Data.Staff?.self),
] }
public var Staff: Data.Staff? { data["Staff"] }
/// Staff
public struct Staff: AniListAPI.SelectionSet {
public static var selections: [Selection] { [
.field("Native", Data.Staff.Native?.self),
] }
public var native: Data.Staff.Native { data ["Native"] }
/// Native
public struct Native: AniListAPI.SelectionSet {
// ...snip
}
}
} I'd much prefer just enforcing that we make field names camelCased, but would like feedback on if this is acceptable to consumers. |
@AnthonyMDev I would be happy with the first option, the automatic conversion to camelCase 👍 I'll be sure to keep filing feedback about the alpha! It's looking good so far migrating from v0.x using Swift scripting. I can't do much yet without operation variables but I saw those are on the way. Honestly the biggest hurdle I had so far was figuring out exactly how to set up codegen. I was getting some strange results due to file paths, but the example project from #2152 (comment) helped 😄 |
Okay great! In that case this is going to be easy and I'll have it in the Alpha 2!
Yeah, I'm, getting operation variables done today! Once they are up, you can use the And, I agree we need much better documentation for onboarding. We are hoping to package the codegen and distribute it as a CLI, so the Swift Scripting won't be required. We really like using it personally, but are finding it's a barrier to entry for a lot of others. Thanks for being an early user! |
This has been merged into the |
I went ahead and released Alpha 2 today, so you can just rely on the tagged |
Thanks! I’ll try out the new alpha soon, hopefully in the next few days 👍 |
Bug report
When generating code from a GraphQL schema that has
PascalCase
query / mutation names, the generated code does not compile because of "ambiguous use of..." errors.Versions
Please fill in the versions you're currently using:
apollo-ios
SDK version: v1.0.0-alpha.1Steps to reproduce
PascalCase
operation names. In my case, https://graphql.anilist.co/ (GraphiQL here: https://anilist.co/graphiql)Staff
queryThe generated code looks like this:
This code doesn't compile because of the naming collision between
public var Staff
andpublic struct Staff
.The same query resulted in code that compiled successfully using apollo-ios v0.x.
Further details
I'm able to work around this by using aliases on all operations. If I tweak the example above:
This generates code that compiles:
This is less than ideal, since I'm likely to forget to alias new queries I write 😅
The text was updated successfully, but these errors were encountered: