Skip to content

Commit e25d913

Browse files
authored
Merge pull request #1038 from mindmind/main
fix: use the correct name of enum, if the field name and the enum name are different (yup).
2 parents 7cb81bf + 9022a56 commit e25d913

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/yup/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ function shapeFields(fields: readonly (FieldDefinitionNode | InputValueDefinitio
301301

302302
if (config.namingConvention?.enumValues)
303303
value = convertNameParts(defaultValue.value, resolveExternalModuleAndFn(config.namingConvention?.enumValues), config?.namingConvention?.transformUnderscore);
304-
305-
fieldSchema = `${fieldSchema}.default(${visitor.convertName(field.name.value)}.${value})`;
304+
const enumName = field.type?.type?.name.value ?? field.name.value
305+
fieldSchema = `${fieldSchema}.default(${visitor.convertName(enumName)}.${value})`;
306306
}
307307
else {
308308
fieldSchema = `${fieldSchema}.default("${escapeGraphQLCharacters(defaultValue.value)}")`;

tests/yup.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,6 +1610,7 @@ describe('yup', () => {
16101610
}
16111611
input PageInput {
16121612
pageType: PageType! = PUBLIC
1613+
customPageType: PageType! = PUBLIC
16131614
greeting: String = "Hello"
16141615
score: Int = 100
16151616
ratio: Float = 0.5
@@ -1633,6 +1634,7 @@ describe('yup', () => {
16331634
expect(result.content).toContain('export function PageInputSchema(): yup.ObjectSchema<PageInput>');
16341635

16351636
expect(result.content).toContain('pageType: PageTypeSchema.nonNullable().default(PageType.Public)');
1637+
expect(result.content).toContain('customPageType: PageTypeSchema.nonNullable().default(PageType.Public)');
16361638
expect(result.content).toContain('greeting: yup.string().defined().nullable().default("Hello").optional()');
16371639
expect(result.content).toContain('score: yup.number().defined().nullable().default(100).optional()');
16381640
expect(result.content).toContain('ratio: yup.number().defined().nullable().default(0.5).optional()');

0 commit comments

Comments
 (0)