Skip to content

Instantly share code, notes, and snippets.

@jferrettiboke
Last active May 2, 2017 20:00
Show Gist options
  • Save jferrettiboke/d025812ce97042930f4ca84fa11b9a10 to your computer and use it in GitHub Desktop.
Save jferrettiboke/d025812ce97042930f4ca84fa11b9a10 to your computer and use it in GitHub Desktop.
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