apollographql / apollographql/apollo-tooling

Autogenerated enum conflicts with existing enum

Open
#583 1 comment 0 reactions 0 assignees View on GitHub
:tada: feature 🤖 component - codegen
Dominant language
TypeScript
Stars
3k
Forks
460
PR merge metrics
No merged PRs in 30d

Description

# What

When a `schema.json` defines something like

```
"kind": "ENUM",
"name": "Role",
"description": null,
"fields": [],
"inputFields": [],
"interfaces": [],
"enumValues": [
...
]
```

the resulting Swift code looks like
```
public enum Role: RawRepresentable, Equatable, Apollo.JSONDecodable, Apollo.JSONEncodable {
...
}
```
When used in an app that's been around for a while, it's likely an enum with the same name will already be defined, so the two will conflict.

# Current Solutions

There are now a couple paths forward:

1. Rename `Role` on the server.
1. Rename the existing `Role` enum on the client.

Neither are ideal of course.

# Proposed Solutions

I think a reasonably clean solution would be to provide something similar to `--customScalarsPrefix`, but where it prefixes enums. In my personal scenario, I would simply provide `"Apollo"` for that config, giving me `public enum ApolloRole`, which I could then map to my existing role if needed.

- [x] feature

Contributor guide

Open the contributing guide

Research direction

Start by tracing how schema.json enum definitions become generated Swift enums, using the existing customScalarsPrefix configuration as the closest reference. Done means a configuration can prefix generated enum names, producing output such as ApolloRole without conflicting with an existing Role enum.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.