1- import { DeclarationBlock , indent } from '@graphql-codegen/visitor-plugin-common' ;
1+ import { DeclarationBlock , convertNameParts , indent } from '@graphql-codegen/visitor-plugin-common' ;
22import type {
33 EnumTypeDefinitionNode ,
44 FieldDefinitionNode ,
@@ -15,6 +15,7 @@ import {
1515 Kind ,
1616} from 'graphql' ;
1717
18+ import { resolveExternalModuleAndFn } from '@graphql-codegen/plugin-helpers' ;
1819import type { ValidationSchemaPluginConfig } from '../config' ;
1920import { buildApi , formatDirectiveConfig } from '../directive' ;
2021import { BaseSchemaVisitor } from '../schema_visitor' ;
@@ -282,8 +283,19 @@ function generateFieldTypeMyZodSchema(config: ValidationSchemaPluginConfig, visi
282283 if ( defaultValue ?. kind === Kind . INT || defaultValue ?. kind === Kind . FLOAT || defaultValue ?. kind === Kind . BOOLEAN )
283284 appliedDirectivesGen = `${ appliedDirectivesGen } .default(${ defaultValue . value } )` ;
284285
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+ }
287299 }
288300
289301 if ( isNonNullType ( parentType ) ) {
0 commit comments