dotansimha / dotansimha/graphql-code-generator

[visitor-plugin-common] parseEnumValue ignore enum mapping if name and value are the same

Open
#5,726 1 comment 4 reactions 0 assignees View on GitHub
core stage/1-reproduction
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

Description

I want to to ask about this specific line of code. Basically we ignore the enum if the name and value are the same
https://github.com/dotansimha/graphql-code-generator/blob/e947f8e393e04dfd52f78bbb35b7e3e6af825c4f/packages/plugins/other/visitor-plugin-common/src/enum-values.ts#L27

For example in the test code below `HR` is excluded from `mappedValues` although I think this is a valid use case. I tried to remove the check but it affected other part of the code base. Do you have any suggestions how we can support the use case where enum value and enum name are the same? Thanks.
Notes: At the moment my work around is changing the enum name from HR to HUMAN_RESOURCE ...

```typescript
const schemaWithEnumValues = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Query',
fields: {
department: {
type: new GraphQLEnumType({
name: 'Department',
values: {
HR: {
value: 'HR',
},
FINANCE: {
value: 'Finance',
},
},
}),
},
},
}),
});

it('should respect enum values from schema and escape it if needed', () => {
const result = parseEnumValues({
schema: schemaWithEnumValues,
mapOrStr: {},
ignoreEnumValuesFromSchema: false,
});

expect(result).toEqual({
Department: {
isDefault: false,
typeIdentifier: 'Department',
sourceFile: null,
importIdentifier: null,
sourceIdentifier: null,
mappedValues: {
FINANCE: 'Finance',
},
},
});
});
```

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.