Skip to content

Commit

Permalink
Allows resolvers to be used with mocks (#9)
Browse files Browse the repository at this point in the history
Previously mocks would overwrite any resolvers, now they are only used when there is no resolve function.
  • Loading branch information
rdrey authored and helfer committed May 26, 2016
1 parent 2a4a419 commit a056dd2
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 a056dd2

Please sign in to comment.