@@ -88,6 +88,32 @@ export const YupSchemaVisitor = (schema: GraphQLSchema, config: ValidationSchema
8888 const name = visitor . convertName ( node . name . value ) ;
8989 importTypes . push ( name ) ;
9090
91+ // Building schema for field arguments.
92+ const argumentBlocks = visitor . buildArgumentsSchemaBlock ( node , ( typeName , field ) => {
93+ importTypes . push ( typeName ) ;
94+ const args = field . arguments ?? [ ] ;
95+ const shape = args . map ( field => generateFieldYupSchema ( config , visitor , field , 2 ) ) . join ( ',\n' ) ;
96+ switch ( config . validationSchemaExportType ) {
97+ case 'const' :
98+ return new DeclarationBlock ( { } )
99+ . export ( )
100+ . asKind ( 'const' )
101+ . withName ( `${ typeName } Schema: yup.ObjectSchema<${ typeName } >` )
102+ . withContent ( [ `yup.object({` , shape , '})' ] . join ( '\n' ) ) . string ;
103+
104+ case 'function' :
105+ default :
106+ return new DeclarationBlock ( { } )
107+ . export ( )
108+ . asKind ( 'function' )
109+ . withName ( `${ typeName } Schema(): yup.ObjectSchema<${ typeName } >` )
110+ . withBlock ( [ indent ( `return yup.object({` ) , shape , indent ( '})' ) ] . join ( '\n' ) ) . string ;
111+ }
112+ } ) ;
113+ const appendArguments = argumentBlocks ? '\n' + argumentBlocks : '' ;
114+
115+ // Building schema for fields.
116+
91117 const shape = node . fields
92118 ?. map ( field => {
93119 const fieldSchema = generateFieldYupSchema ( config , visitor , field , 2 ) ;
@@ -97,33 +123,37 @@ export const YupSchemaVisitor = (schema: GraphQLSchema, config: ValidationSchema
97123
98124 switch ( config . validationSchemaExportType ) {
99125 case 'const' :
100- return new DeclarationBlock ( { } )
101- . export ( )
102- . asKind ( 'const' )
103- . withName ( `${ name } Schema: yup.ObjectSchema<${ name } >` )
104- . withContent (
105- [
106- `yup.object({` ,
107- indent ( `__typename: yup.string<'${ node . name . value } '>().optional(),` , 2 ) ,
108- shape ,
109- '})' ,
110- ] . join ( '\n' )
111- ) . string ;
126+ return (
127+ new DeclarationBlock ( { } )
128+ . export ( )
129+ . asKind ( 'const' )
130+ . withName ( `${ name } Schema: yup.ObjectSchema<${ name } >` )
131+ . withContent (
132+ [
133+ `yup.object({` ,
134+ indent ( `__typename: yup.string<'${ node . name . value } '>().optional(),` , 2 ) ,
135+ shape ,
136+ '})' ,
137+ ] . join ( '\n' )
138+ ) . string + appendArguments
139+ ) ;
112140
113141 case 'function' :
114142 default :
115- return new DeclarationBlock ( { } )
116- . export ( )
117- . asKind ( 'function' )
118- . withName ( `${ name } Schema(): yup.ObjectSchema<${ name } >` )
119- . withBlock (
120- [
121- indent ( `return yup.object({` ) ,
122- indent ( `__typename: yup.string<'${ node . name . value } '>().optional(),` , 2 ) ,
123- shape ,
124- indent ( '})' ) ,
125- ] . join ( '\n' )
126- ) . string ;
143+ return (
144+ new DeclarationBlock ( { } )
145+ . export ( )
146+ . asKind ( 'function' )
147+ . withName ( `${ name } Schema(): yup.ObjectSchema<${ name } >` )
148+ . withBlock (
149+ [
150+ indent ( `return yup.object({` ) ,
151+ indent ( `__typename: yup.string<'${ node . name . value } '>().optional(),` , 2 ) ,
152+ shape ,
153+ indent ( '})' ) ,
154+ ] . join ( '\n' )
155+ ) . string + appendArguments
156+ ) ;
127157 }
128158 } ) ,
129159 } ,
0 commit comments