apollographql / apollographql/apollo-tooling

[codegen][swift] code generation issue on `init` enum case

Open
#2,337 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
3k
Forks
460
PR merge metrics
No merged PRs in 30d

Description

**Intended outcome:**

On swift code generation, when schema contains an enumeration with the word `init`, the swift generated code failed to build since init is a reserved word.

**Actual outcome:**

On schema, an enumeration declared like this :
```graphql
enum CEventType {
init
addUser
removeUser
}
```
When the swift code is generated, except for the enum case, there is no escaping put on the word `init` for init method, rawValue, equatable protocole and allCases implementation.

![Capture d’écran 2021-05-26 à 14 27 57](https://user-images.githubusercontent.com/33665639/119659849-e124f200-be2e-11eb-9f59-fb497ccae0f2.png)

An issue has been closed on the apollo-ios repository since it's appear to be an issue in the codegen part. https://github.com/apollographql/apollo-ios/issues/1427

Since the current API I use is on a production environment it appear to be difficult to change the name of the enum, so I hope you can get look on this. Thanks.

**How to reproduce**

Create schema with the given enum and generate the swift code and try to build.

**Versions**

The version used to reproduce this bug is the Apollo-tooling version included in the apollo-ios library run script. Here I use the version 0.43.0 of `apollo-ios` library (through cocoapods) that seems to use `apollo-tooling` version 2.32.1

Contributor guide

Open the contributing guide

Research direction

Start in the Apollo tooling Swift code-generation path and reproduce the issue with the provided CEventType schema using Apollo tooling 2.32.1. Done means every generated use of the init enum case, including the initializer, rawValue, Equatable, and allCases implementations, is escaped so the Swift output builds.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift, typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.