diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6d5af23f822..7698f45bd12 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,7 @@
- Fix visitEnumValue to allow modifying the enum value
[@danielrearden](https://github.com/danielrearden) in [#1003](https://github.com/ardatan/graphql-tools/pull/1391)
- Export `generateProxyingResolvers` from `@graphql-tools/wrap`.
+- Fix `stitchSchemas` from `@graphql-tools/stitch` from the case there the typeDefs array is empty. [#1575](https://github.com/ardatan/graphql-tools/pull/1575)
### 5.0.0
diff --git a/packages/stitch/src/stitchSchemas.ts b/packages/stitch/src/stitchSchemas.ts
index 27ad05f31a3..da547adc9b1 100644
--- a/packages/stitch/src/stitchSchemas.ts
+++ b/packages/stitch/src/stitchSchemas.ts
@@ -51,7 +51,7 @@ export function stitchSchemas({
}
let schemaLikeObjects: Array = [...subschemas];
- if (typeDefs) {
+ if ((typeDefs && !Array.isArray(typeDefs)) || (Array.isArray(typeDefs) && typeDefs.length)) {
schemaLikeObjects.push(buildDocumentFromTypeDefinitions(typeDefs, parseOptions));
}
if (types != null) {
diff --git a/packages/stitch/tests/stitchSchemas.test.ts b/packages/stitch/tests/stitchSchemas.test.ts
index 65e53038d2d..928682c3c3f 100644
--- a/packages/stitch/tests/stitchSchemas.test.ts
+++ b/packages/stitch/tests/stitchSchemas.test.ts
@@ -2982,6 +2982,36 @@ fragment BookingFragment on Booking {
});
});
+ describe('empty typeDefs array', () => {
+ test('works', async () => {
+ const typeDefs = `
+ type Query {
+ book: Book
+ }
+ type Book {
+ category: String!
+ }
+ `;
+ let schema = makeExecutableSchema({ typeDefs });
+
+ const resolvers = {
+ Query: {
+ book: () => ({ category: 'Test' }),
+ },
+ };
+
+ schema = stitchSchemas({
+ schemas: [schema],
+ resolvers,
+ typeDefs: [],
+ });
+
+ const result = await graphql(schema, '{ book { cat: category } }');
+
+ expect(result.data.book.cat).toBe('Test');
+ });
+ });
+
describe('new root type name', () => {
test('works', async () => {
let bookSchema = makeExecutableSchema({