Skip to content

Commit d27ed53

Browse files
authored
fix(stitch): add __typename for mutations (#2467)
* fix(stitch): add __typename for mutations * Create giant-cooks-melt.md
1 parent d62b23f commit d27ed53

File tree

3 files changed

+66
-4
lines changed

3 files changed

+66
-4
lines changed

.changeset/giant-cooks-melt.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@graphql-tools/stitch": patch
3+
---
4+
5+
fix(stitch): add __typename for mutations
6+
7+
fix related to #2349

packages/stitch/src/stitchingInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ export function completeStitchingInfo(
233233
schema: GraphQLSchema
234234
): StitchingInfo {
235235
const selectionSetsByType = Object.create(null);
236-
[schema.getQueryType(), schema.getMutationType].forEach(rootType => {
236+
[schema.getQueryType(), schema.getMutationType()].forEach(rootType => {
237237
if (rootType) {
238238
selectionSetsByType[rootType.name] = parseSelectionSet('{ __typename }', { noLocation: true });
239239
}

packages/stitch/tests/nestedRootTypes.test.ts

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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';
33
import { graphql } from 'graphql';
44

55
describe('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

Comments
 (0)