@@ -91,50 +91,65 @@ const generateInputObjectFieldYupSchema = (
9191 field : InputValueDefinitionNode ,
9292 indentCount : number
9393) : string => {
94- let gen = generateInputObjectFieldTypeZodSchema ( config , tsVisitor , schema , field . type ) ;
95- if ( config . directives && field . directives ) {
96- const formatted = formatDirectiveConfig ( config . directives ) ;
97- gen += buildApi ( formatted , field . directives ) ;
98- }
94+ const gen = generateInputObjectFieldTypeZodSchema ( config , tsVisitor , schema , field , field . type ) ;
9995 return indent ( `${ field . name . value } : ${ maybeLazy ( field . type , gen ) } ` , indentCount ) ;
10096} ;
10197
10298const generateInputObjectFieldTypeZodSchema = (
10399 config : ValidationSchemaPluginConfig ,
104100 tsVisitor : TsVisitor ,
105101 schema : GraphQLSchema ,
102+ field : InputValueDefinitionNode ,
106103 type : TypeNode ,
107104 parentType ?: TypeNode
108105) : string => {
109106 if ( isListType ( type ) ) {
110- const gen = generateInputObjectFieldTypeZodSchema ( config , tsVisitor , schema , type . type , type ) ;
107+ const gen = generateInputObjectFieldTypeZodSchema ( config , tsVisitor , schema , field , type . type , type ) ;
111108 if ( ! isNonNullType ( parentType ) ) {
112- return `z.array(${ maybeLazy ( type . type , gen ) } ).nullish()` ;
109+ const arrayGen = `z.array(${ maybeLazy ( type . type , gen ) } )` ;
110+ const maybeLazyGen = applyDirectives ( config , field , arrayGen ) ;
111+ return `${ maybeLazyGen } .nullish()` ;
113112 }
114113 return `z.array(${ maybeLazy ( type . type , gen ) } )` ;
115114 }
116115 if ( isNonNullType ( type ) ) {
117- const gen = generateInputObjectFieldTypeZodSchema ( config , tsVisitor , schema , type . type , type ) ;
116+ const gen = generateInputObjectFieldTypeZodSchema ( config , tsVisitor , schema , field , type . type , type ) ;
118117 return maybeLazy ( type . type , gen ) ;
119118 }
120119 if ( isNamedType ( type ) ) {
121120 const gen = generateNameNodeZodSchema ( config , tsVisitor , schema , type . name ) ;
121+ if ( isListType ( parentType ) ) {
122+ return `${ gen } .nullable()` ;
123+ }
124+ const appliedDirectivesGen = applyDirectives ( config , field , gen ) ;
122125 if ( isNonNullType ( parentType ) ) {
123126 if ( config . notAllowEmptyString === true ) {
124127 const tsType = tsVisitor . scalars [ type . name . value ] ;
125128 if ( tsType === 'string' ) return `${ gen } .min(1)` ;
126129 }
127- return gen ;
130+ return appliedDirectivesGen ;
128131 }
129132 if ( isListType ( parentType ) ) {
130- return `${ gen } .nullable()` ;
133+ return `${ appliedDirectivesGen } .nullable()` ;
131134 }
132- return `${ gen } .nullish()` ;
135+ return `${ appliedDirectivesGen } .nullish()` ;
133136 }
134137 console . warn ( 'unhandled type:' , type ) ;
135138 return '' ;
136139} ;
137140
141+ const applyDirectives = (
142+ config : ValidationSchemaPluginConfig ,
143+ field : InputValueDefinitionNode ,
144+ gen : string
145+ ) : string => {
146+ if ( config . directives && field . directives ) {
147+ const formatted = formatDirectiveConfig ( config . directives ) ;
148+ return gen + buildApi ( formatted , field . directives ) ;
149+ }
150+ return gen ;
151+ } ;
152+
138153const generateNameNodeZodSchema = (
139154 config : ValidationSchemaPluginConfig ,
140155 tsVisitor : TsVisitor ,
0 commit comments