Last active
May 2, 2017 19:15
-
-
Save jferrettiboke/f2318bfc376e23faeb6c8b34bfcaf28f 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
// 1. Importamos dependencias. | |
const express = require('express'); | |
const bodyParser = require('body-parser'); | |
const { graphqlExpress } = require('graphql-server-express'); | |
const { makeExecutableSchema } = require('graphql-tools'); | |
// 2. Definimos los diferentes tipos en nuestro schema. | |
const typeDefs = [ | |
` | |
type Query { | |
hello: String | |
} | |
schema { | |
query: Query | |
} | |
` | |
]; | |
// 3. Creamos las funciones de resolución. | |
const resolvers = { | |
Query: { | |
hello: () => 'Hello world!' | |
} | |
}; | |
// 4. Creamos un schema GraphQL ejecutable a partir del schema definido y las | |
// funciones de resolución. | |
const executableSchema = makeExecutableSchema({ typeDefs, resolvers }); | |
// 5. Creamos una aplicación con Express. | |
const app = express(); | |
// 6. Creamos un endpoint en nuestra aplicación Express llamado `/graphql`. | |
// Usamos `body-parser`. Usamos `graphqlExpress` para crear un servidor en | |
// Express usando el schema ejecutable anteriormente creado. | |
app.use( | |
'/graphql', | |
bodyParser.json(), | |
graphqlExpress({ schema: executableSchema }) | |
); | |
// 7. Ponemos a escuchar nuestra aplicación en el puerto 4000. Imprimimos por | |
// terminal/consola un mensaje. | |
app.listen(4000, () => console.log('Ready! localhost:4000/graphql')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment