Skip to content

Commit

Permalink
Allows resolvers to be used with mocks
Browse files Browse the repository at this point in the history
Previously mocks would overwrite any resolvers. Includes test.
  • Loading branch information
Rainer Dreyer committed May 26, 2016
1 parent 2a4a419 commit 2f5ced2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/apolloServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export default function apolloServer(options, ...rest) {
addMockFunctionsToSchema({
schema: executableSchema,
mocks: myMocks,
preserveResolvers: true,
});
} else {
// this is just basics, makeExecutableSchema should catch the rest
Expand Down
34 changes: 34 additions & 0 deletions test/testApolloServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,40 @@ describe('ApolloServer', () => {
return expect(res.body.data).to.deep.equal(expected);
});
});
it('can mock a schema and use partially implemented resolvers', () => {
const app = express();
const mockServer = apolloServer({
schema: `
type Query {
mocked: String
resolved(name: String): String
}
schema {
query: Query
}
`,
mocks: {
String: () => 'Mocked fallback',
},
resolvers: {
Query: {
resolved(root, { name }) {
return `Hello, ${name}!`;
},
},
},
});
app.use('/graphql', mockServer);
const expected = {
mocked: 'Mocked fallback',
resolved: 'Hello, world!',
};
return request(app).get(
'/graphql?query={mocked resolved(name: "world")}'
).then((res) => {
return expect(res.body.data).to.deep.equal(expected);
});
});
it('can mock a schema with unions', () => {
const app = express();
const schema = `
Expand Down

0 comments on commit 2f5ced2

Please sign in to comment.