Last active
June 11, 2019 15:21
-
-
Save marcolz/2b2c0843242bd8601bd43a1e75e04e4d to your computer and use it in GitHub Desktop.
Mocking GraphQL with express-graphql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could you give an example on how to initialize the mocks object?