@@ -29,18 +29,22 @@ export const YupSchemaVisitor = (schema: GraphQLSchema, config: ValidationSchema
29
29
}
30
30
return [ importYup ] ;
31
31
} ,
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
+ } ,
44
48
InputObjectTypeDefinition : ( node : InputObjectTypeDefinitionNode ) => {
45
49
const name = tsVisitor . convertName ( node . name . value ) ;
46
50
importTypes . push ( name ) ;
@@ -102,7 +106,7 @@ export const YupSchemaVisitor = (schema: GraphQLSchema, config: ValidationSchema
102
106
. withContent ( `yup.mixed().oneOf([${ values } ])` ) . string ;
103
107
} ,
104
108
UnionTypeDefinition : ( node : UnionTypeDefinitionNode ) => {
105
- if ( ! node . types ) return ;
109
+ if ( ! node . types || ! config . withObjectType ) return ;
106
110
107
111
const unionName = tsVisitor . convertName ( node . name . value ) ;
108
112
importTypes . push ( unionName ) ;
0 commit comments