Skip to content

Instantly share code, notes, and snippets.

@barsumek
Last active November 22, 2018 10:54
Show Gist options
  • Save barsumek/d795a4bcb7d3f9c5c3944a4acbec2d94 to your computer and use it in GitHub Desktop.
Save barsumek/d795a4bcb7d3f9c5c3944a4acbec2d94 to your computer and use it in GitHub Desktop.
Detox your GraphQL: Mock schema
const { ApolloServer } = require("apollo-server-express");
const { buildClientSchema } = require("graphql");
const { resolvers } = require("./schema");
const introspectedSchema = require("./schemaExample.json");
const PORT = 8089;
function createServerWithMockedSchema(customMocks = {}) {
const schema = buildClientSchema(introspectedSchema);
const server = new ApolloServer({
schema: schema,
resolvers: resolvers,
mocks: customMocks,
playground: {
endpoint: `http://localhost:${PORT}/graphql`
}
});
return server;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment