From 4d2679c1d96991d4e4bdcba6e8f18d5eb5c0d5dd Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Thu, 28 Feb 2019 15:21:12 -0500 Subject: [PATCH] Allow empty typeDefs --- packages/core/src/graphql-module.ts | 8 +++++--- packages/core/tests/graphql-module.spec.ts | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) 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(); + }); });