dotansimha / dotansimha/graphql-code-generator-community

[flow] Enum type values start with _ will generate incorrect Object.freeze

Open
#199 0 comments 2 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
137
Forks
195
Avg merge
6h 20m
Merged PRs (30d)
16

Description

### Describe the bug

A valid GraphQL enum value type can be` /^[_a-zA-Z][_a-zA-Z0-9]*$/ `, thus definition like this is valid enum type
```
enum TestEnum {
_1_foo
_2_bar
_3_baz
_garment_on_hanger
_oog
_overweight
}
```
The Enum object can be generated without issue, but the key is violating Javascript syntax.

### Your Example Website or App

https://codesandbox.io/s/reverent-thunder-4gcxom?file=/schema.graphql:109-183

### Steps to Reproduce the Bug or Issue

1. Go to [codesandbox](https://codesandbox.io/s/reverent-thunder-4gcxom?file=/schema.graphql:109-183)
2. Run `yarn generate`
3. Open `type.js`
4. Hover on errors related to enum, they are `SyntaxError: identifier starts immediately after numeric literal`, refer to [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Identifier_after_number)
5. Copy enum Object.freeze and paste it in [jsfiddle](https://jsfiddle.net/)
Screen Shot 2022-07-01 at 1 30 42 PM

### Expected behavior

Generate correct Javascript syntax enum Object under this scanario.

### Screenshots or Videos

_No response_

### Platform

- OS: macOS
- NodeJS: 18.5.0
- `graphql` version: 16.5.0
- `@graphql-codegen/cli`: 2.6.4
- `@graphql-codegen/flow`:2.2.13
- `@graphql-codegen/flow-operations`:2.2.13

### Codegen Config File

schema: schema.graphql
generates:
types.js:
plugins:
- flow
- flow-operations

### Additional context

_No response_

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.