Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stitchSchemas for when empty array of typeDefs are passed #1575

Merged
merged 1 commit into from Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,7 @@
- Fix visitEnumValue to allow modifying the enum value <br/>
[@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

Expand Down
2 changes: 1 addition & 1 deletion packages/stitch/src/stitchSchemas.ts
Expand Up @@ -51,7 +51,7 @@ export function stitchSchemas({
}

let schemaLikeObjects: Array<GraphQLSchema | SubschemaConfig | DocumentNode | GraphQLNamedType> = [...subschemas];
if (typeDefs) {
if ((typeDefs && !Array.isArray(typeDefs)) || (Array.isArray(typeDefs) && typeDefs.length)) {
schemaLikeObjects.push(buildDocumentFromTypeDefinitions(typeDefs, parseOptions));
}
if (types != null) {
Expand Down
30 changes: 30 additions & 0 deletions packages/stitch/tests/stitchSchemas.test.ts
Expand Up @@ -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({
Expand Down