@@ -700,6 +700,125 @@ describe('Codegen Executor', () => {
700700 } ) ;
701701 } ) ;
702702
703+ describe ( 'Parsed GraphQLSchema input' , ( ) => {
704+ it ( 'should accept a GraphQLSchema instance as root schema' , async ( ) => {
705+ const schema = buildSchema ( SIMPLE_TEST_SCHEMA ) ;
706+ const { result } = await executeCodegen ( {
707+ schema,
708+ generates : {
709+ 'out1.ts' : { plugins : [ 'typescript' ] } ,
710+ } ,
711+ } ) ;
712+
713+ expect ( result . length ) . toBe ( 1 ) ;
714+ expect ( result [ 0 ] . content ) . toContain ( 'MyType' ) ;
715+ } ) ;
716+
717+ it ( 'should accept a GraphQLSchema instance in an array' , async ( ) => {
718+ const schema = buildSchema ( SIMPLE_TEST_SCHEMA ) ;
719+ const { result } = await executeCodegen ( {
720+ schema : [ schema ] ,
721+ generates : {
722+ 'out1.ts' : { plugins : [ 'typescript' ] } ,
723+ } ,
724+ } ) ;
725+
726+ expect ( result . length ) . toBe ( 1 ) ;
727+ expect ( result [ 0 ] . content ) . toContain ( 'MyType' ) ;
728+ } ) ;
729+
730+ it ( 'should merge a GraphQLSchema instance with an SDL string' , async ( ) => {
731+ const schema = buildSchema ( SIMPLE_TEST_SCHEMA ) ;
732+ const { result } = await executeCodegen ( {
733+ schema : [ schema , `type Post { id: ID! }` ] ,
734+ generates : {
735+ 'out1.ts' : { plugins : [ 'typescript' ] } ,
736+ } ,
737+ } ) ;
738+
739+ expect ( result . length ) . toBe ( 1 ) ;
740+ expect ( result [ 0 ] . content ) . toContain ( 'MyType' ) ;
741+ expect ( result [ 0 ] . content ) . toContain ( 'Post' ) ;
742+ } ) ;
743+
744+ it ( 'should merge two GraphQLSchema instances' , async ( ) => {
745+ const schemaA = buildSchema ( SIMPLE_TEST_SCHEMA ) ;
746+ const schemaB = buildSchema ( `type Post { id: ID! } type Query { posts: [Post] }` ) ;
747+ const { result } = await executeCodegen ( {
748+ schema : [ schemaA , schemaB ] ,
749+ generates : {
750+ 'out1.ts' : { plugins : [ 'typescript' ] } ,
751+ } ,
752+ } ) ;
753+
754+ expect ( result . length ) . toBe ( 1 ) ;
755+ expect ( result [ 0 ] . content ) . toContain ( 'MyType' ) ;
756+ expect ( result [ 0 ] . content ) . toContain ( 'Post' ) ;
757+ } ) ;
758+
759+ it ( 'should accept a GraphQLSchema instance as output-level schema' , async ( ) => {
760+ const schema = buildSchema ( SIMPLE_TEST_SCHEMA ) ;
761+ const { result } = await executeCodegen ( {
762+ generates : {
763+ 'out1.ts' : {
764+ schema,
765+ plugins : [ 'typescript' ] ,
766+ } ,
767+ } ,
768+ } ) ;
769+
770+ expect ( result . length ) . toBe ( 1 ) ;
771+ expect ( result [ 0 ] . content ) . toContain ( 'MyType' ) ;
772+ } ) ;
773+
774+ it ( 'should merge root SDL string with output-level GraphQLSchema instance' , async ( ) => {
775+ const outputSchema = buildSchema ( `type Post { id: ID! } type Query { posts: [Post] }` ) ;
776+ const { result } = await executeCodegen ( {
777+ schema : SIMPLE_TEST_SCHEMA ,
778+ generates : {
779+ 'out1.ts' : {
780+ schema : outputSchema ,
781+ plugins : [ 'typescript' ] ,
782+ } ,
783+ } ,
784+ } ) ;
785+
786+ expect ( result . length ) . toBe ( 1 ) ;
787+ expect ( result [ 0 ] . content ) . toContain ( 'MyType' ) ;
788+ expect ( result [ 0 ] . content ) . toContain ( 'Post' ) ;
789+ } ) ;
790+
791+ it ( 'should work with documents when schema is a GraphQLSchema instance' , async ( ) => {
792+ const schema = buildSchema ( SIMPLE_TEST_SCHEMA ) ;
793+ const { result } = await executeCodegen ( {
794+ schema,
795+ documents : `query root { f }` ,
796+ generates : {
797+ 'out1.ts' : { plugins : [ 'typescript' , 'typescript-operations' ] } ,
798+ } ,
799+ } ) ;
800+
801+ expect ( result . length ) . toBe ( 1 ) ;
802+ expect ( result [ 0 ] . content ) . toContain ( 'RootQuery' ) ;
803+ } ) ;
804+
805+ it ( 'should preserve custom scalars from a GraphQLSchema instance' , async ( ) => {
806+ const schema = buildSchema ( `
807+ scalar DateTime
808+ type Query { now: DateTime }
809+ ` ) ;
810+ const { result } = await executeCodegen ( {
811+ schema,
812+ generates : {
813+ 'out1.ts' : { plugins : [ 'typescript' ] } ,
814+ } ,
815+ } ) ;
816+
817+ expect ( result . length ) . toBe ( 1 ) ;
818+ expect ( result [ 0 ] . content ) . toContain ( 'DateTime' ) ;
819+ } ) ;
820+ } ) ;
821+
703822 describe ( 'Custom schema loader' , ( ) => {
704823 it ( 'Should allow custom loaders to load schema on root level' , async ( ) => {
705824 await executeCodegen ( {
0 commit comments