File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ interface InputObjectFieldGeneratorParams {
2323 indentCount ?: number ;
2424}
2525
26- export const ImportYup = ( ) : string => `import * as yup from 'yup'`
26+ export const ImportYup = ( ) : string => `import * as yup from 'yup'` ;
2727
2828export class YupGenerator {
2929 private inputObjects : InputObjectTypeDefinitionNode [ ] ;
@@ -37,9 +37,14 @@ export class YupGenerator {
3737 }
3838
3939 public generate ( ) : string {
40- return this . inputObjects
41- . map ( ( inputObject ) => this . generateInputObjectYupSchema ( inputObject ) )
42- . join ( "\n\n" ) ;
40+ return [
41+ ...Object . values ( this . enums ) . map (
42+ ( enumdef ) => `export const ${ enumdef . name . value } Schema = yup.mixed().oneOf(Object.values(${ enumdef . name . value } ))`
43+ ) ,
44+ ...this . inputObjects . map ( ( inputObject ) =>
45+ this . generateInputObjectYupSchema ( inputObject )
46+ ) ,
47+ ] . join ( "\n\n" ) ;
4348 }
4449
4550 protected generateInputObjectYupSchema (
@@ -112,7 +117,7 @@ export class YupGenerator {
112117 }
113118 if ( this . enums [ node . value ] ) {
114119 const enumdef = this . enums [ node . value ] ;
115- return `yup.mixed().oneOf(Object.values( ${ enumdef . name . value } )) ` ;
120+ return `${ enumdef . name . value } Schema ` ;
116121 }
117122 if ( this . scalars [ node . value ] ) {
118123 console . warn ( "unhandled scalar:" , this . scalars [ node . value ] ) ;
You can’t perform that action at this time.
0 commit comments