@@ -412,6 +412,70 @@ describe('zod', () => {
412412 }
413413 } ) ;
414414 } ) ;
415+ describe ( 'PR #112' , ( ) => {
416+ it ( 'with notAllowEmptyString' , async ( ) => {
417+ const schema = buildSchema ( /* GraphQL */ `
418+ input UserCreateInput {
419+ profile: String! @constraint(maxLength: 5000)
420+ age: Int!
421+ }
422+
423+ directive @constraint(maxLength: Int!) on INPUT_FIELD_DEFINITION
424+ ` ) ;
425+ const result = await plugin (
426+ schema ,
427+ [ ] ,
428+ {
429+ schema : 'zod' ,
430+ notAllowEmptyString : true ,
431+ directives : {
432+ constraint : {
433+ maxLength : [ 'max' , '$1' , 'Please input less than $1' ] ,
434+ } ,
435+ } ,
436+ } ,
437+ { }
438+ ) ;
439+ const wantContains = [
440+ 'export function UserCreateInputSchema(): z.ZodObject<Properties<UserCreateInput>>' ,
441+ 'profile: z.string().max(5000, "Please input less than 5000").min(1),' ,
442+ ] ;
443+ for ( const wantContain of wantContains ) {
444+ expect ( result . content ) . toContain ( wantContain ) ;
445+ }
446+ } ) ;
447+
448+ it ( 'without notAllowEmptyString' , async ( ) => {
449+ const schema = buildSchema ( /* GraphQL */ `
450+ input UserCreateInput {
451+ profile: String! @constraint(maxLength: 5000)
452+ age: Int!
453+ }
454+
455+ directive @constraint(maxLength: Int!) on INPUT_FIELD_DEFINITION
456+ ` ) ;
457+ const result = await plugin (
458+ schema ,
459+ [ ] ,
460+ {
461+ schema : 'zod' ,
462+ directives : {
463+ constraint : {
464+ maxLength : [ 'max' , '$1' , 'Please input less than $1' ] ,
465+ } ,
466+ } ,
467+ } ,
468+ { }
469+ ) ;
470+ const wantContains = [
471+ 'export function UserCreateInputSchema(): z.ZodObject<Properties<UserCreateInput>>' ,
472+ 'profile: z.string().max(5000, "Please input less than 5000"),' ,
473+ ] ;
474+ for ( const wantContain of wantContains ) {
475+ expect ( result . content ) . toContain ( wantContain ) ;
476+ }
477+ } ) ;
478+ } ) ;
415479 describe ( 'GraphQl Type Support' , ( ) => {
416480 const schema = buildSchema ( /* GraphQL */ `
417481 input ScalarsInput {
0 commit comments