1- import { makeExecutableSchema } from " @graphql-tools/schema" ;
2- import { stitchSchemas } from " @graphql-tools/stitch" ;
1+ import { makeExecutableSchema } from ' @graphql-tools/schema' ;
2+ import { stitchSchemas } from ' @graphql-tools/stitch' ;
33import { graphql } from 'graphql' ;
44
55describe ( 'nested root types' , ( ) => {
@@ -9,12 +9,20 @@ describe('nested root types', () => {
99 schema1Boolean: Boolean
1010 schema1Query: Query
1111 }
12+ type Mutation {
13+ schema1Boolean: Boolean
14+ schema1Mutation: Mutation
15+ }
1216 ` ,
1317 resolvers : {
1418 Query : {
1519 schema1Boolean : ( ) => true ,
1620 schema1Query : ( ) => ( { } ) ,
1721 } ,
22+ Mutation : {
23+ schema1Boolean : ( ) => true ,
24+ schema1Mutation : ( ) => ( { } ) ,
25+ } ,
1826 } ,
1927 } ) ;
2028
@@ -24,20 +32,28 @@ describe('nested root types', () => {
2432 schema2Boolean: Boolean
2533 schema2Query: Query
2634 }
35+ type Mutation {
36+ schema2Boolean: Boolean
37+ schema2Mutation: Mutation
38+ }
2739 ` ,
2840 resolvers : {
2941 Query : {
3042 schema2Boolean : ( ) => true ,
3143 schema2Query : ( ) => ( { } ) ,
3244 } ,
45+ Mutation : {
46+ schema2Boolean : ( ) => true ,
47+ schema2Mutation : ( ) => ( { } ) ,
48+ } ,
3349 } ,
3450 } ) ;
3551
3652 const stitchedSchema = stitchSchemas ( {
3753 subschemas : [ schema1 , schema2 ] ,
3854 } ) ;
3955
40- it ( 'works to nest root field ' , async ( ) => {
56+ it ( 'works to nest Query ' , async ( ) => {
4157 const query = `
4258 query {
4359 schema1Query {
@@ -75,4 +91,43 @@ describe('nested root types', () => {
7591 const result = await graphql ( stitchedSchema , query ) ;
7692 expect ( result ) . toEqual ( expectedResult ) ;
7793 } ) ;
94+
95+ it ( 'works to nest Mutation' , async ( ) => {
96+ const mutation = `
97+ mutation {
98+ schema1Mutation {
99+ schema1Boolean
100+ schema2Mutation {
101+ schema1Boolean
102+ }
103+ }
104+ schema2Mutation {
105+ schema2Boolean
106+ schema1Mutation {
107+ schema2Boolean
108+ }
109+ }
110+ }
111+ ` ;
112+
113+ const expectedResult = {
114+ data : {
115+ schema1Mutation : {
116+ schema1Boolean : true ,
117+ schema2Mutation : {
118+ schema1Boolean : true ,
119+ } ,
120+ } ,
121+ schema2Mutation : {
122+ schema2Boolean : true ,
123+ schema1Mutation : {
124+ schema2Boolean : true ,
125+ } ,
126+ } ,
127+ } ,
128+ } ;
129+
130+ const result = await graphql ( stitchedSchema , mutation ) ;
131+ expect ( result ) . toEqual ( expectedResult ) ;
132+ } ) ;
78133} ) ;
0 commit comments