apollographql / apollographql/apollo-tooling
Swift codegen uses pascalCase for operationClassName that may have unintuitive result
- Dominant language
- TypeScript
- Stars
- 3k
- Forks
- 460
- PR merge metrics
- No merged PRs in 30d
Description
Swift codegen: https://github.com/apollographql/apollo-tooling/blob/master/packages/apollo-codegen-swift/src/helpers.ts#L121 uses pascalCase for operationClassName.
However, in example such as: https://github.com/apollographql/apollo-ios/blob/main/Sources/StarWarsAPI/API.swift#L4432 It lower case `ID` to `Id`.
This is actually expected if you buy into the strict pascalCase. However, you can see for https://github.com/apollographql/apollo-ios/blob/main/Sources/StarWarsAPI/API.swift#L610, the `IDs` didn't lower case to `Ids`.
The reason is because the regex `change-case` uses to split strings: https://github.com/blakeembrey/change-case/blob/master/packages/no-case/src/index.ts#L11 will split the input into:
["Hero", "And", "Friends", "Names", "With", "I", "Ds"]
Thus, composed back without lowering case for "IDs".
I am hesitant to call this a bug in either Apollo codegen or `change-case` as the `pascalCase` method need to recognize the original format and that is ill-defined in nature anyway. But want to highlight these "nice" mutations in names to `pascalCase` or `camelCase` can have unintended consequences.
Contributor guide
Research direction
Start in packages/apollo-codegen-swift/src/helpers.ts at the operationClassName pascalCase call, then compare the linked API.swift examples for ID and IDs. Read the linked change-case no-case regex to understand how the names are split. Done means an agreed, documented behavior for acronym handling and corresponding codegen coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift, typescript
- Domain
- devtools, tooling
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100