File tree Expand file tree Collapse file tree 3 files changed +15
-19
lines changed Expand file tree Collapse file tree 3 files changed +15
-19
lines changed Original file line number Diff line number Diff line change @@ -97,15 +97,11 @@ export const MyZodSchemaVisitor = (schema: GraphQLSchema, config: ValidationSche
97
97
const unionElements = node . types ?. map ( t => `${ tsVisitor . convertName ( t . name . value ) } Schema()` ) . join ( ', ' ) ;
98
98
const unionElementsCount = node . types ?. length ?? 0 ;
99
99
100
- const union = unionElementsCount > 1 ? `myzod.union([${ unionElements } ])` : unionElements ;
100
+ const union =
101
+ unionElementsCount > 1 ? indent ( `return myzod.union([${ unionElements } ])` ) : indent ( `return ${ unionElements } ` ) ;
101
102
102
- const result = new DeclarationBlock ( { } )
103
- . export ( )
104
- . asKind ( 'const' )
105
- . withName ( `${ unionName } Schema` )
106
- . withContent ( union ) ;
107
-
108
- return result . string ;
103
+ return new DeclarationBlock ( { } ) . export ( ) . asKind ( 'function' ) . withName ( `${ unionName } Schema()` ) . withBlock ( union )
104
+ . string ;
109
105
} ,
110
106
} ;
111
107
} ;
@@ -201,7 +197,7 @@ const generateNameNodeMyZodSchema = (
201
197
202
198
if ( typ ?. astNode ?. kind === 'UnionTypeDefinition' ) {
203
199
const enumName = tsVisitor . convertName ( typ . astNode . name . value ) ;
204
- return `${ enumName } Schema` ;
200
+ return `${ enumName } Schema() ` ;
205
201
}
206
202
207
203
return myzod4Scalar ( config , tsVisitor , node . value ) ;
Original file line number Diff line number Diff line change @@ -108,15 +108,13 @@ export const YupSchemaVisitor = (schema: GraphQLSchema, config: ValidationSchema
108
108
importTypes . push ( unionName ) ;
109
109
110
110
const unionElements = node . types ?. map ( t => `${ tsVisitor . convertName ( t . name . value ) } Schema()` ) . join ( ', ' ) ;
111
- const unionElementsCount = node . types ?. length ?? 0 ;
112
-
113
- const union = unionElementsCount > 1 ? `union<${ unionName } >(${ unionElements } )` : unionElements ;
111
+ const union = indent ( `return union<${ unionName } >(${ unionElements } )` ) ;
114
112
115
113
return new DeclarationBlock ( { } )
116
114
. export ( )
117
- . asKind ( 'const ' )
118
- . withName ( `${ unionName } Schema: yup.BaseSchema<${ unionName } >` )
119
- . withContent ( union ) . string ;
115
+ . asKind ( 'function ' )
116
+ . withName ( `${ unionName } Schema() : yup.BaseSchema<${ unionName } >` )
117
+ . withBlock ( union ) . string ;
120
118
} ,
121
119
// ScalarTypeDefinition: (node) => {
122
120
// const decl = new DeclarationBlock({})
@@ -211,7 +209,7 @@ const generateNameNodeYupSchema = (
211
209
212
210
if ( typ ?. astNode ?. kind === 'UnionTypeDefinition' ) {
213
211
const enumName = tsVisitor . convertName ( typ . astNode . name . value ) ;
214
- return `${ enumName } Schema` ;
212
+ return `${ enumName } Schema() ` ;
215
213
}
216
214
217
215
const primitive = yup4Scalar ( config , tsVisitor , node . value ) ;
Original file line number Diff line number Diff line change @@ -108,9 +108,11 @@ export const ZodSchemaVisitor = (schema: GraphQLSchema, config: ValidationSchema
108
108
const unionElements = node . types . map ( t => `${ tsVisitor . convertName ( t . name . value ) } Schema()` ) . join ( ', ' ) ;
109
109
const unionElementsCount = node . types . length ?? 0 ;
110
110
111
- const union = unionElementsCount > 1 ? `z.union([${ unionElements } ])` : unionElements ;
111
+ const union =
112
+ unionElementsCount > 1 ? indent ( `return z.union([${ unionElements } ])` ) : indent ( `return ${ unionElements } ` ) ;
112
113
113
- return new DeclarationBlock ( { } ) . export ( ) . asKind ( 'const' ) . withName ( `${ unionName } Schema` ) . withContent ( union ) . string ;
114
+ return new DeclarationBlock ( { } ) . export ( ) . asKind ( 'function' ) . withName ( `${ unionName } Schema()` ) . withBlock ( union )
115
+ . string ;
114
116
} ,
115
117
} ;
116
118
} ;
@@ -206,7 +208,7 @@ const generateNameNodeZodSchema = (
206
208
207
209
if ( typ ?. astNode ?. kind === 'UnionTypeDefinition' ) {
208
210
const enumName = tsVisitor . convertName ( typ . astNode . name . value ) ;
209
- return `${ enumName } Schema` ;
211
+ return `${ enumName } Schema() ` ;
210
212
}
211
213
212
214
return zod4Scalar ( config , tsVisitor , node . value ) ;
You can’t perform that action at this time.
0 commit comments