Skip to content

Commit

Permalink
Merge pull request #321 from nwfortner/master
Browse files Browse the repository at this point in the history
bug fix. added type check for addMockFunctionsToSchema first arg
  • Loading branch information
DxCx committed May 7, 2017
2 parents 2ab81f6 + 3fa714f commit 1abcfbb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,6 +1,7 @@
# Change log

### vNEXT
* Add argument validation in `addMockFunctionsToSchema` for 'schema' property in parameter object [PR #321](https://github.com/apollographql/graphql-tools/pull/321)

### v0.11.0
* Remove dependency on `graphql-subscription` and use an interface for PubSub [PR #295](https://github.com/apollographql/graphql-tools/pull/295)
Expand Down
4 changes: 3 additions & 1 deletion src/mock.ts
Expand Up @@ -43,9 +43,11 @@ function addMockFunctionsToSchema({ schema, mocks = {}, preserveResolvers = fals
}

if (!schema) {
// XXX should we check that schema is an instance of GraphQLSchema?
throw new Error('Must provide schema to mock');
}
if (!(schema instanceof GraphQLSchema)) {
throw new Error('Value at "schema" must be of type GraphQLSchema');
}
if (!isObject(mocks)) {
throw new Error('mocks must be of type Object');
}
Expand Down
5 changes: 5 additions & 0 deletions src/test/testMocking.ts
Expand Up @@ -90,6 +90,11 @@ describe('Mock', () => {
.to.throw('Must provide schema to mock');
});

it('throws an error if the property "schema" on the first argument is not of type GraphQLSchema', () => {
expect(() => (<any> addMockFunctionsToSchema)({ schema: {}}))
.to.throw('Value at "schema" must be of type GraphQLSchema');
});

it('throws an error if second argument is not a Map', () => {
const jsSchema = buildSchemaFromTypeDefinitions(shorthand);
expect(() => (<any> addMockFunctionsToSchema)({ schema: jsSchema, mocks: ['a'] }))
Expand Down

0 comments on commit 1abcfbb

Please sign in to comment.