@@ -539,6 +539,88 @@ describe('myzod', () => {
539539 expect ( result . content ) . toContain ( wantContain ) ;
540540 }
541541 } ) ;
542+ it ( 'generate object type contains interface type' , async ( ) => {
543+ const schema = buildSchema ( /* GraphQL */ `
544+ interface Book {
545+ title: String!
546+ author: Author!
547+ }
548+
549+ type Textbook implements Book {
550+ title: String!
551+ author: Author!
552+ courses: [String!]!
553+ }
554+
555+ type ColoringBook implements Book {
556+ title: String!
557+ author: Author!
558+ colors: [String!]!
559+ }
560+
561+ type Author {
562+ books: [Book!]
563+ name: String
564+ }
565+ ` ) ;
566+ const result = await plugin (
567+ schema ,
568+ [ ] ,
569+ {
570+ schema : 'myzod' ,
571+ withInterfaceType : true ,
572+ withObjectType : true ,
573+ } ,
574+ { }
575+ ) ;
576+ const wantContains = [
577+ [
578+ 'export function BookSchema(): myzod.Type<Book> {' ,
579+ 'return myzod.object({' ,
580+ 'title: myzod.string(),' ,
581+ 'author: AuthorSchema()' ,
582+ '})' ,
583+ '}' ,
584+ ] ,
585+
586+ [
587+ 'export function TextbookSchema(): myzod.Type<Textbook> {' ,
588+ 'return myzod.object({' ,
589+ "__typename: myzod.literal('Textbook').optional()," ,
590+ 'title: myzod.string(),' ,
591+ 'author: AuthorSchema(),' ,
592+ 'courses: myzod.array(myzod.string())' ,
593+ '})' ,
594+ '}' ,
595+ ] ,
596+
597+ [
598+ 'export function ColoringBookSchema(): myzod.Type<ColoringBook> {' ,
599+ 'return myzod.object({' ,
600+ "__typename: myzod.literal('ColoringBook').optional()," ,
601+ 'title: myzod.string(),' ,
602+ 'author: AuthorSchema(),' ,
603+ 'colors: myzod.array(myzod.string())' ,
604+ '})' ,
605+ '}' ,
606+ ] ,
607+
608+ [
609+ 'export function AuthorSchema(): myzod.Type<Author> {' ,
610+ 'return myzod.object({' ,
611+ "__typename: myzod.literal('Author').optional()" ,
612+ 'books: myzod.array(BookSchema()).optional().nullable()' ,
613+ 'name: myzod.string().optional().nullable()' ,
614+ '})' ,
615+ '}' ,
616+ ] ,
617+ ] ;
618+ for ( const wantContain of wantContains ) {
619+ for ( const wantContainLine of wantContain ) {
620+ expect ( result . content ) . toContain ( wantContainLine ) ;
621+ }
622+ }
623+ } ) ;
542624 } ) ;
543625
544626 describe ( 'with withObjectType' , ( ) => {
0 commit comments