Skip to content

Instantly share code, notes, and snippets.

@marcolz
Last active June 11, 2019 15:21
Show Gist options
  • Save marcolz/2b2c0843242bd8601bd43a1e75e04e4d to your computer and use it in GitHub Desktop.
Save marcolz/2b2c0843242bd8601bd43a1e75e04e4d to your computer and use it in GitHub Desktop.
Mocking GraphQL with express-graphql
const express = require('express')
const graphqlHTTP = require('express-graphql')
const { buildSchema } = require('graphql')
const { addMockFunctionsToSchema } = require('graphql-tools')
const app = express()
const schema = buildSchema(`
...your schema here...
`)
const mocks = {
// ...your mocks here...
}
addMockFunctionsToSchema({
schema,
mocks,
})
app.use('/graphql', graphqlHTTP({
schema: builtSchema,
graphiql: true,
}))
app.listen(4000)
@simondegheselle
Copy link

simondegheselle commented Feb 28, 2017

Could you give an example on how to initialize the mocks object?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment