@@ -338,4 +338,75 @@ describe('valibot', () => {
338338 "
339339 ` )
340340 } ) ;
341+ it . todo ( 'with typesPrefix' )
342+ it . todo ( 'with typesSuffix' )
343+ it . todo ( 'with default input values' )
344+ describe ( 'issues #19' , ( ) => {
345+ it ( 'string field' , async ( ) => {
346+ const schema = buildSchema ( /* GraphQL */ `
347+ input UserCreateInput {
348+ profile: String @constraint(minLength: 1, maxLength: 5000)
349+ }
350+ directive @constraint(minLength: Int!, maxLength: Int!) on INPUT_FIELD_DEFINITION
351+ ` ) ;
352+ const result = await plugin (
353+ schema ,
354+ [ ] ,
355+ {
356+ schema : 'valibot' ,
357+ directives : {
358+ constraint : {
359+ minLength : [ 'minLength' , '$1' , 'Please input more than $1' ] ,
360+ maxLength : [ 'maxLength' , '$1' , 'Please input less than $1' ] ,
361+ } ,
362+ } ,
363+ } ,
364+ { } ,
365+ ) ;
366+ expect ( result . content ) . toMatchInlineSnapshot ( `
367+ "
368+
369+ export function UserCreateInputSchema(): v.GenericSchema<UserCreateInput> {
370+ return v.object({
371+ profile: v.nullish(v.pipe(v.string(), v.minLength(1, "Please input more than 1"), v.maxLength(5000, "Please input less than 5000")))
372+ })
373+ }
374+ "
375+ ` )
376+ } ) ;
377+
378+ it ( 'not null field' , async ( ) => {
379+ const schema = buildSchema ( /* GraphQL */ `
380+ input UserCreateInput {
381+ profile: String! @constraint(minLength: 1, maxLength: 5000)
382+ }
383+ directive @constraint(minLength: Int!, maxLength: Int!) on INPUT_FIELD_DEFINITION
384+ ` ) ;
385+ const result = await plugin (
386+ schema ,
387+ [ ] ,
388+ {
389+ schema : 'valibot' ,
390+ directives : {
391+ constraint : {
392+ minLength : [ 'minLength' , '$1' , 'Please input more than $1' ] ,
393+ maxLength : [ 'maxLength' , '$1' , 'Please input less than $1' ] ,
394+ } ,
395+ } ,
396+ } ,
397+ { } ,
398+ ) ;
399+
400+ expect ( result . content ) . toMatchInlineSnapshot ( `
401+ "
402+
403+ export function UserCreateInputSchema(): v.GenericSchema<UserCreateInput> {
404+ return v.object({
405+ profile: v.pipe(v.string(), v.minLength(1, "Please input more than 1"), v.maxLength(5000, "Please input less than 5000"))
406+ })
407+ }
408+ "
409+ ` )
410+ } ) ;
411+ } )
341412} )
0 commit comments