Skip to content

[typescript-operations] Fix enumValues not considering namingConvention in certain scenarios#10656

Merged
eddeee888 merged 10 commits intomaster-nextfrom
master-next-fix-enum-values-naming-convention
Mar 30, 2026
Merged

[typescript-operations] Fix enumValues not considering namingConvention in certain scenarios#10656
eddeee888 merged 10 commits intomaster-nextfrom
master-next-fix-enum-values-naming-convention

Conversation

@eddeee888
Copy link
Copy Markdown
Collaborator

@eddeee888 eddeee888 commented Mar 30, 2026

Description

Enum type naming convention was not being applied consistently across imports, Input, Variables and Result.
This causes some edge cases where the enum does not get referred to correctly, causing type issues.

Related #10496
Issues: #10471

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Unit test

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 30, 2026

🦋 Changeset detected

Latest commit: 40d48c3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@graphql-codegen/visitor-plugin-common Patch
@graphql-codegen/typescript-operations Patch
@graphql-codegen/typescript Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Comment on lines +770 to +782
this.config.enumValues = parseEnumValues({
schema: _schema,
mapOrStr: rawConfig.enumValues,
naming: {
convert: this.config.convert,
options: {
typesPrefix: this.config.typesPrefix,
typesSuffix: this.config.typesSuffix,
useTypesPrefix: this.config.enumPrefix,
useTypesSuffix: this.config.enumSuffix,
},
},
});
Copy link
Copy Markdown
Collaborator Author

@eddeee888 eddeee888 Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enumValues now parses the type with naming convention, so we need to pass naming convention config in.

IMO the naming config and function are a bit confusing to use atm. However, we can fix it internally later to keep scope maintainable in this PR/major release

Comment on lines +22 to +27
options: {
typesPrefix: string;
typesSuffix: string;
useTypesPrefix?: boolean;
useTypesSuffix?: boolean;
};
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grouping options here make it a bit easier to read

Comment on lines -240 to -268
const convertName = ({
convert,
options,
}: {
options: {
typesPrefix: string;
useTypesPrefix?: boolean;
typesSuffix: string;
useTypesSuffix?: boolean;
};
convert: () => string;
}): string => {
const useTypesPrefix = typeof options.useTypesPrefix === 'boolean' ? options.useTypesPrefix : true;
const useTypesSuffix = typeof options.useTypesSuffix === 'boolean' ? options.useTypesSuffix : true;

let convertedName = '';

if (useTypesPrefix) {
convertedName += options.typesPrefix;
}

convertedName += convert();

if (useTypesSuffix) {
convertedName += options.typesSuffix;
}

return convertedName;
};
Copy link
Copy Markdown
Collaborator Author

@eddeee888 eddeee888 Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is moved to visitor-plugin-common here

return allEnums
.filter(enumName => !enumName.startsWith('__'))
.reduce((prev, enumName) => {
.reduce<ParsedEnumValuesMap>((prev, enumName) => {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer using .reduce's generic to avoid as SomeType usage at the bottom

Comment on lines +64 to +73
function convertNameParts(str: string, func: (str: string) => string, removeUnderscore = false): string {
if (removeUnderscore) {
return func(str);
}

return str
.split('_')
.map(s => func(s))
.join('_');
}
Copy link
Copy Markdown
Collaborator Author

@eddeee888 eddeee888 Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This convertNameParts function was previously in another file here, but is only ever used in this function. May as well move it here to keep things closer together.

});

expect(result).not.toEqual({
expect(result).toEqual({
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these tests have been turned to possible case, to be more explicit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant