Skip to content

Commit

Permalink
Allow empty typeDefs
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Feb 28, 2019
1 parent 4818184 commit 4d2679c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/core/src/graphql-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,9 +552,11 @@ export class GraphQLModule<Config = any, Session = any, Context = any> {
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;
}
Expand Down
17 changes: 17 additions & 0 deletions packages/core/tests/graphql-module.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

0 comments on commit 4d2679c

Please sign in to comment.