diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d5af23f822..1ae3110b27f 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. ### 5.0.0 diff --git a/packages/stitch/src/stitchSchemas.ts b/packages/stitch/src/stitchSchemas.ts index 27ad05f31a3..1f633531351 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 && 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({