diff --git a/packages/core/src/graphql-module.ts b/packages/core/src/graphql-module.ts index c3396588b62..faf6a73c74b 100644 --- a/packages/core/src/graphql-module.ts +++ b/packages/core/src/graphql-module.ts @@ -552,9 +552,11 @@ export class GraphQLModule { if (typeof typeDefsDefinitions === 'string') { typeDefs = parse(typeDefsDefinitions); } else if (Array.isArray(typeDefsDefinitions)) { - typeDefs = mergeTypeDefs(typeDefsDefinitions, { - useSchemaDefinition: false, - }); + if (typeDefsDefinitions.length) { + typeDefs = mergeTypeDefs(typeDefsDefinitions, { + useSchemaDefinition: false, + }); + } } else if (typeDefsDefinitions) { typeDefs = typeDefsDefinitions; } diff --git a/packages/core/tests/graphql-module.spec.ts b/packages/core/tests/graphql-module.spec.ts index b49f1a3b40d..9a05c773c47 100644 --- a/packages/core/tests/graphql-module.spec.ts +++ b/packages/core/tests/graphql-module.spec.ts @@ -1282,4 +1282,21 @@ describe('GraphQLModule', () => { }); expect(data.foo).toBe('FOO'); }); + it('should generate schemaless module if empty typeDefs and resolvers specified', async () => { + const { schema: schemaA } = new GraphQLModule({ + typeDefs: [], + resolvers: {}, + }); + expect(schemaA).toBeNull(); + const { schema: schemaB } = new GraphQLModule({ + typeDefs: '', + resolvers: {}, + }); + expect(schemaB).toBeNull(); + const { schema: schemaC } = new GraphQLModule({ + typeDefs: [''], + resolvers: {}, + }); + expect(schemaC).toBeNull(); + }); });