@@ -40,7 +40,7 @@ export const YupSchemaVisitor = (
4040
4141 const shape = node . fields
4242 ?. map ( ( field ) =>
43- generateInputObjectFieldYupSchema ( tsVisitor , schema , field , 2 )
43+ generateInputObjectFieldYupSchema ( config , tsVisitor , schema , field , 2 )
4444 )
4545 . join ( ",\n" ) ;
4646
@@ -63,9 +63,7 @@ export const YupSchemaVisitor = (
6363 . withName ( `${ enumname } Schema` )
6464 . withContent (
6565 `yup.mixed().oneOf([${ node . values
66- ?. map (
67- ( enumOption ) => `'${ enumOption . name . value } '`
68- )
66+ ?. map ( ( enumOption ) => `'${ enumOption . name . value } '` )
6967 . join ( ", " ) } ])`
7068 ) . string ;
7169 }
@@ -108,13 +106,15 @@ export const YupSchemaVisitor = (
108106} ;
109107
110108const generateInputObjectFieldYupSchema = (
109+ config : ValidationSchemaPluginConfig ,
111110 tsVisitor : TsVisitor ,
112111 schema : GraphQLSchema ,
113112 field : InputValueDefinitionNode ,
114113 indentCount : number
115114) : string => {
116115 // TOOD(codehex): handle directive
117116 const gen = generateInputObjectFieldTypeYupSchema (
117+ config ,
118118 tsVisitor ,
119119 schema ,
120120 field . type
@@ -126,17 +126,19 @@ const generateInputObjectFieldYupSchema = (
126126} ;
127127
128128const generateInputObjectFieldTypeYupSchema = (
129+ config : ValidationSchemaPluginConfig ,
129130 tsVisitor : TsVisitor ,
130131 schema : GraphQLSchema ,
131132 type : TypeNode ,
132133 parentType ?: TypeNode
133134) : string => {
134135 if ( isListType ( type ) ) {
135136 const gen = generateInputObjectFieldTypeYupSchema (
137+ config ,
136138 tsVisitor ,
137139 schema ,
138140 type . type ,
139- type ,
141+ type
140142 ) ;
141143 if ( ! isNonNullType ( parentType ) ) {
142144 return `yup.array().of(${ maybeLazy ( type . type , gen ) } ).optional()` ;
@@ -145,21 +147,23 @@ const generateInputObjectFieldTypeYupSchema = (
145147 }
146148 if ( isNonNullType ( type ) ) {
147149 const gen = generateInputObjectFieldTypeYupSchema (
150+ config ,
148151 tsVisitor ,
149152 schema ,
150153 type . type ,
151- type ,
154+ type
152155 ) ;
153156 return maybeLazy ( type . type , `${ gen } .defined()` ) ;
154157 }
155158 if ( isNamedType ( type ) ) {
156- return generateNameNodeYupSchema ( tsVisitor , schema , type . name ) ;
159+ return generateNameNodeYupSchema ( config , tsVisitor , schema , type . name ) ;
157160 }
158161 console . warn ( "unhandled type:" , type ) ;
159162 return "" ;
160163} ;
161164
162165const generateNameNodeYupSchema = (
166+ config : ValidationSchemaPluginConfig ,
163167 tsVisitor : TsVisitor ,
164168 schema : GraphQLSchema ,
165169 node : NameNode
@@ -176,7 +180,8 @@ const generateNameNodeYupSchema = (
176180 return `${ enumName } Schema` ;
177181 }
178182
179- return yup4Scalar ( tsVisitor , node . value ) ;
183+ const primitive = yup4Scalar ( tsVisitor , node . value ) ;
184+ return config . yup ?. strict ? `${ primitive } .strict(true)` : primitive ;
180185} ;
181186
182187const maybeLazy = ( type : TypeNode , schema : string ) : string => {
0 commit comments