dotansimha / dotansimha/graphql-code-generator

`namingConvention` config is not applied when `enumsAsTypes: true`

Open
#8,170 1 comment 3 reactions 0 assignees View on GitHub
core
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

Description

### Describe the bug

I want to have an enum that is outputted as a Union type in kebab-case.

So that the following enum:
```gql
enum Options {
CHILD_SEAT
PET_CAGE_SMALL
PET_CAGE_LARGE
}
```

renders into:
```typescript
export type Options = 'child-seat' | 'pet-cage-small' | 'pet-cage-large'
```

But I wasn't able to find a way to achieve this. The `namingConvention` config seems to have no effect on union types.

### Your Example Website or App

https://codesandbox.io/s/serverless-microservice-fgh29z

### Steps to Reproduce the Bug or Issue

1. Have an enum with any values in the schema
2. Use `enumsAsTypes: true` alongside `namingConvention.enumValues: lodash#kebabCase`
3. Observe that generated union type uses the same case as defined in the GQL schema

### Expected behavior

As a user, I expect `namingConvention` to have an effect when used together with `enumsAsTypes: true`, but I see that it doesn't.

### Screenshots or Videos

_No response_

### Platform

- OS: macOS
- NodeJS: 16.16
- `graphql` version: 16.5.0
- `@graphql-codegen/cli` version: 2.9.1
- `@graphql-codegen/typescript` version: 2.7.2

### Codegen Config File

```yml
schema: schema.graphql
generates:
types.ts:
config:
enumsAsTypes: true
namingConvention:
enumValues: lodash#kebabCase
plugins:
- typescript
```

### Additional context

- It's impossible to have kebab-case in the GQL schema enum
- The types are to be used over existing DB, so it has to be snake case to avoid major refactoring

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.