Closed zshlomyz closed 1 year ago
Sorry for the late reply @zshlomyz
So I've looked into it and enumValues
actually mean enumKeys
. Values are set by the typescript generated file because we reference it. This is equivalent to enumValues
config from nameConvention
in typescript plugin config
Assuming we have the following schema:
enum MyEnum {
MY_ENUM_VAL
}
type SomeType {
enum: MyEnum
}
and the following config:
overwrite: true
schema: schema.graphql
documents:
- 'src/**/*.ts'
- 'src/**/*.tsx'
- '!src/**/generated/*'
generates:
./src/types/generated/graphql.ts:
plugins:
- 'typescript'
- 'typescript-operations'
config:
namingConvention:
enumValues: keep # <-- equivalent of 'enumValues: keep' in 'typescript-mock-data' plugin
src/mocks/generated/graphql.ts:
plugins:
- typescript-mock-data:
enumValues: keep
typesFile: '../../types/generated/graphql.ts'
Here are the generated files I've got: Types:
export enum MyEnum {
MY_ENUM_VAL = 'MY_ENUM_VAL',
}
export type SomeType = {
__typename?: 'SomeType';
enum?: Maybe<MyEnum>;
};
Mock:
export const aSomeType = (overrides?: Partial<SomeType>): SomeType => {
return {
enum: overrides && overrides.hasOwnProperty('enum') ? overrides.enum! : MyEnum.MY_ENUM_VAL,
};
};
As you can see the mock file uses MyEnum.MY_ENUM_VAL
to keep the same behaviour as typescript plugin.
If you want pascal case, just remove enumValues
config it's the default (or set it to pascal-case#pascalCase
)
Thanks @ardeois !!
Hi, My config:
As u can see, I've settled the typenames and enumValues to keep, but yet, the mock data is generated using a pascal-case like this -
MyEnum.MY_ENUM_VAL
instead ofMyEnum.MyEnumKey
when my enum looks like that:I suspect that it related to the issue that the generated value use the value of the enum instead of the key, as u can see in this line - https://github.com/ardeois/graphql-codegen-typescript-mock-data/blob/2521deac47f7974b5af9241c1ca5e3c8e266115a/src/index.ts#L50 Am I correct? should I create a PR to fix that? Thanks