1
- import { DeclarationBlock , indent } from '@graphql-codegen/visitor-plugin-common' ;
1
+ import { DeclarationBlock , convertNameParts , indent } from '@graphql-codegen/visitor-plugin-common' ;
2
2
import type {
3
3
EnumTypeDefinitionNode ,
4
4
FieldDefinitionNode ,
@@ -14,7 +14,6 @@ import type {
14
14
import {
15
15
Kind ,
16
16
} from 'graphql' ;
17
- import { pascalCase } from "change-case" ;
18
17
19
18
import type { ValidationSchemaPluginConfig } from '../config' ;
20
19
import { buildApi , formatDirectiveConfig } from '../directive' ;
@@ -28,6 +27,7 @@ import {
28
27
isNamedType ,
29
28
isNonNullType ,
30
29
} from './../graphql' ;
30
+ import { resolveExternalModuleAndFn } from '@graphql-codegen/plugin-helpers' ;
31
31
32
32
export class YupSchemaVisitor extends BaseSchemaVisitor {
33
33
constructor ( schema : GraphQLSchema , config : ValidationSchemaPluginConfig ) {
@@ -285,7 +285,13 @@ function shapeFields(fields: readonly (FieldDefinitionNode | InputValueDefinitio
285
285
286
286
if ( defaultValue ?. kind === Kind . STRING || defaultValue ?. kind === Kind . ENUM ) {
287
287
if ( config . useEnumTypeAsDefaultValue && defaultValue ?. kind !== Kind . STRING ) {
288
- fieldSchema = `${ fieldSchema } .default(${ visitor . convertName ( field . name . value ) } .${ pascalCase ( defaultValue . value ) } )` ;
288
+ let value = convertNameParts ( defaultValue . value , resolveExternalModuleAndFn ( "change-case-all#pascalCase" ) ) ;
289
+
290
+ if ( config . namingConvention ?. enumValues ) {
291
+ value = convertNameParts ( defaultValue . value , resolveExternalModuleAndFn ( config . namingConvention ?. enumValues ) ) ;
292
+ }
293
+
294
+ fieldSchema = `${ fieldSchema } .default(${ visitor . convertName ( field . name . value ) } .${ value } )` ;
289
295
} else {
290
296
fieldSchema = `${ fieldSchema } .default("${ defaultValue . value } ")` ;
291
297
}
0 commit comments