Closed Benoit-ROBIN closed 1 year ago
I'm not sure to follow. The values are not changed because we only use enum keys. What does the generated type looks like?
Pardon my english,
I need to set transformUnderscore
to false because I have underscore in my type's name.
Because of this, the enum generated also keep underscore in key name.
For example, with the plugin typescript
enum PassPunchKind {
MAXIMUM_DAILY_PUNCHES,
MAXIMUM_MONTHLY_PUNCHES,
MAXIMUM_MONTHLY_PUNCHES_ON_FIRM,
MAXIMUM_MONTHLY_PUNCHES_ON_GYM
}
will be transform to
enum PassPunchKind {
MaximumDailyPunches = 'MAXIMUM_DAILY_PUNCHES',
MaximumMonthlyPunches = 'MAXIMUM_MONTHLY_PUNCHES',
MaximumMonthlyPunchesOnFirm = 'MAXIMUM_MONTHLY_PUNCHES_ON_FIRM',
MaximumMonthlyPunchesOnGym = 'MAXIMUM_MONTHLY_PUNCHES_ON_GYM'
}
but with typescript-mock-data the same enum will be used as
export const aPassPunchLimitation = (
overrides?: Partial<PassPunchLimitation>,
_relationshipsToOmit: Array<string> = [],
): PassPunchLimitation => {
const relationshipsToOmit = [..._relationshipsToOmit, 'PassPunchLimitation'];
return {
isReached:
overrides && overrides.hasOwnProperty('isReached')
? overrides.isReached!
: true,
kind:
overrides && overrides.hasOwnProperty('kind')
? overrides.kind!
: PassPunchKind.Maximum_Daily_Punches, // <<<<<------ HERE
nextAvailabilityDate:
overrides && overrides.hasOwnProperty('nextAvailabilityDate')
? overrides.nextAvailabilityDate!
: 'alias',
threshold:
overrides && overrides.hasOwnProperty('threshold')
? overrides.threshold!
: 6720,
};
};
which will cause error because Maximum_Daily_Punches
doesn't exist on PassPunchKind. Instead it should be PassPunchKind.MaximumDailyPunches
.
I tried to force true as second parameter for createNameConverter on this line as in this PR and I have the result expected. So I thought maybe you should use another configuration parameter instead of transformUnderscore
for the enum.
I see, it seems like the PR you are mentionning fixes one issue but adds a new one.
@Benoit-ROBIN The bug should be fixed now with PR https://github.com/ardeois/graphql-codegen-typescript-mock-data/pull/120 Version > 3.3.0
Can you confirm?
@ardeois sorry for the response delay, it's all good, no errors. Thank you for your work 🙏 ❤️
Hi I tried to have my enum generated in pascalCase (key and value), but in my case only the keys are transformed to pascalCase, the value stay in snakeCase. I have seen this pr and I thought maybe it was overwritten accidentally ?
here my config
I have set transformUnderscore to false because I need to keep underscore on my type's name.