Last active
May 2, 2017 20:00
-
-
Save jferrettiboke/d025812ce97042930f4ca84fa11b9a10 to your computer and use it in GitHub Desktop.
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 bodyParser = require('body-parser'); | |
// 1. Importamos `graphiqlExpress`. | |
const { graphqlExpress, graphiqlExpress } = require('graphql-server-express'); | |
const { makeExecutableSchema } = require('graphql-tools'); | |
const typeDefs = [ | |
` | |
type Query { | |
hello: String | |
} | |
schema { | |
query: Query | |
} | |
` | |
]; | |
const resolvers = { | |
Query: { | |
hello: () => 'Hello world!' | |
} | |
}; | |
const executableSchema = makeExecutableSchema({ typeDefs, resolvers }); | |
const app = express(); | |
app.use( | |
'/graphql', | |
bodyParser.json(), | |
graphqlExpress({ schema: executableSchema }) | |
); | |
// 2. Creamos un endpoint llamado `/graphiql` para GraphiQL. Usamos | |
// `graphiqlExpress` e indicamos el slug dónde se encuentra nuestro servidor | |
// GraphQL (/graphql). | |
app.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql' })); | |
app.listen(4000, () => console.log('Ready! localhost:4000/graphiql')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment