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 ,
@@ -15,6 +15,7 @@ import {
15
15
Kind ,
16
16
} from 'graphql' ;
17
17
18
+ import { resolveExternalModuleAndFn } from '@graphql-codegen/plugin-helpers' ;
18
19
import type { ValidationSchemaPluginConfig } from '../config' ;
19
20
import { buildApi , formatDirectiveConfig } from '../directive' ;
20
21
import { BaseSchemaVisitor } from '../schema_visitor' ;
@@ -282,8 +283,19 @@ function generateFieldTypeMyZodSchema(config: ValidationSchemaPluginConfig, visi
282
283
if ( defaultValue ?. kind === Kind . INT || defaultValue ?. kind === Kind . FLOAT || defaultValue ?. kind === Kind . BOOLEAN )
283
284
appliedDirectivesGen = `${ appliedDirectivesGen } .default(${ defaultValue . value } )` ;
284
285
285
- if ( defaultValue ?. kind === Kind . STRING || defaultValue ?. kind === Kind . ENUM )
286
- appliedDirectivesGen = `${ appliedDirectivesGen } .default("${ escapeGraphQLCharacters ( defaultValue . value ) } ")` ;
286
+ if ( defaultValue ?. kind === Kind . STRING || defaultValue ?. kind === Kind . ENUM ) {
287
+ if ( config . useEnumTypeAsDefaultValue && defaultValue ?. kind !== Kind . STRING ) {
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
+ appliedDirectivesGen = `${ appliedDirectivesGen } .default(${ visitor . convertName ( type . name . value ) } .${ value } )` ;
294
+ }
295
+ else {
296
+ appliedDirectivesGen = `${ appliedDirectivesGen } .default("${ escapeGraphQLCharacters ( defaultValue . value ) } ")` ;
297
+ }
298
+ }
287
299
}
288
300
289
301
if ( isNonNullType ( parentType ) ) {
0 commit comments