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

Allows resolvers to be used with mocks #9

Merged
merged 1 commit into from
May 26, 2016
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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