@@ -459,6 +459,89 @@ describe('yup', () => {
459
459
expect ( result . content ) . not . toContain ( wantNotContain ) ;
460
460
}
461
461
} ) ;
462
+ it ( 'generate object type contains interface type' , async ( ) => {
463
+ const schema = buildSchema ( /* GraphQL */ `
464
+ interface Book {
465
+ title: String!
466
+ author: Author!
467
+ }
468
+
469
+ type Textbook implements Book {
470
+ title: String!
471
+ author: Author!
472
+ courses: [String!]!
473
+ }
474
+
475
+ type ColoringBook implements Book {
476
+ title: String!
477
+ author: Author!
478
+ colors: [String!]!
479
+ }
480
+
481
+ type Author {
482
+ books: [Book!]
483
+ name: String
484
+ }
485
+ ` ) ;
486
+ const result = await plugin (
487
+ schema ,
488
+ [ ] ,
489
+ {
490
+ schema : 'yup' ,
491
+ withInterfaceType : true ,
492
+ withObjectType : true ,
493
+ } ,
494
+ { }
495
+ ) ;
496
+ const wantContains = [
497
+ [
498
+ 'export function BookSchema(): yup.ObjectSchema<Book> {' ,
499
+ 'return yup.object({' ,
500
+ 'title: yup.string().defined().nonNullable(),' ,
501
+ 'author: AuthorSchema().nonNullable()' ,
502
+ '})' ,
503
+ '}' ,
504
+ ] ,
505
+
506
+ [
507
+ 'export function TextbookSchema(): yup.ObjectSchema<Textbook> {' ,
508
+ 'return yup.object({' ,
509
+ "__typename: yup.string<'Textbook'>().optional()," ,
510
+ 'title: yup.string().defined().nonNullable(),' ,
511
+ 'author: AuthorSchema().nonNullable(),' ,
512
+ 'courses: yup.array(yup.string().defined().nonNullable()).defined()' ,
513
+ '})' ,
514
+ '}' ,
515
+ ] ,
516
+
517
+ [
518
+ 'export function ColoringBookSchema(): yup.ObjectSchema<ColoringBook> {' ,
519
+ 'return yup.object({' ,
520
+ "__typename: yup.string<'ColoringBook'>().optional()," ,
521
+ 'title: yup.string().defined().nonNullable(),' ,
522
+ 'author: AuthorSchema().nonNullable(),' ,
523
+ 'colors: yup.array(yup.string().defined().nonNullable()).defined()' ,
524
+ '})' ,
525
+ '}' ,
526
+ ] ,
527
+
528
+ [
529
+ 'export function AuthorSchema(): yup.ObjectSchema<Author> {' ,
530
+ 'return yup.object({' ,
531
+ "__typename: yup.string<'Author'>().optional()," ,
532
+ 'books: yup.array(BookSchema().nonNullable()).defined().nullable().optional(),' ,
533
+ 'name: yup.string().defined().nullable().optional()' ,
534
+ '})' ,
535
+ '}' ,
536
+ ] ,
537
+ ] ;
538
+
539
+ for ( const wantContain of wantContains ) {
540
+ for ( const wantContainLine of wantContain ) {
541
+ expect ( result . content ) . toContain ( wantContainLine ) ;
542
+ }
543
+ }
544
+ } ) ;
462
545
} ) ;
463
546
464
547
describe ( 'with withObjectType' , ( ) => {
0 commit comments