@@ -29,18 +29,22 @@ export const YupSchemaVisitor = (schema: GraphQLSchema, config: ValidationSchema
2929 }
3030 return [ importYup ] ;
3131 } ,
32- initialEmit : ( ) : string =>
33- '\n' +
34- new DeclarationBlock ( { } )
35- . asKind ( 'function' )
36- . withName ( 'union<T>(...schemas: ReadonlyArray<yup.SchemaOf<T>>): yup.BaseSchema<T>' )
37- . withBlock (
38- [
39- indent ( 'return yup.mixed().test({' ) ,
40- indent ( 'test: (value) => schemas.some((schema) => schema.isValidSync(value))' , 2 ) ,
41- indent ( '})' ) ,
42- ] . join ( '\n' )
43- ) . string ,
32+ initialEmit : ( ) : string => {
33+ if ( ! config . withObjectType ) return '' ;
34+ return (
35+ '\n' +
36+ new DeclarationBlock ( { } )
37+ . asKind ( 'function' )
38+ . withName ( 'union<T>(...schemas: ReadonlyArray<yup.SchemaOf<T>>): yup.BaseSchema<T>' )
39+ . withBlock (
40+ [
41+ indent ( 'return yup.mixed().test({' ) ,
42+ indent ( 'test: (value) => schemas.some((schema) => schema.isValidSync(value))' , 2 ) ,
43+ indent ( '})' ) ,
44+ ] . join ( '\n' )
45+ ) . string
46+ ) ;
47+ } ,
4448 InputObjectTypeDefinition : ( node : InputObjectTypeDefinitionNode ) => {
4549 const name = tsVisitor . convertName ( node . name . value ) ;
4650 importTypes . push ( name ) ;
@@ -102,7 +106,7 @@ export const YupSchemaVisitor = (schema: GraphQLSchema, config: ValidationSchema
102106 . withContent ( `yup.mixed().oneOf([${ values } ])` ) . string ;
103107 } ,
104108 UnionTypeDefinition : ( node : UnionTypeDefinitionNode ) => {
105- if ( ! node . types ) return ;
109+ if ( ! node . types || ! config . withObjectType ) return ;
106110
107111 const unionName = tsVisitor . convertName ( node . name . value ) ;
108112 importTypes . push ( unionName ) ;
0 commit comments