-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
30 lines (24 loc) · 885 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const express = require('express');
const cors = require("cors");
const bodyParser = require('body-parser');
const { graphqlExpress, graphiqlExpress } = require('apollo-server-express');
const { makeExecutableSchema } = require('graphql-tools');
const { importSchema } = require('graphql-import');
const resolvers = require('./resolvers').resolvers;
// Put together a schema
const schema = makeExecutableSchema({
typeDefs: importSchema('./schema.graphql'),
resolvers,
});
// Initialize the app
const app = express();
// enable cors
app.use('*', cors());
// The GraphQL endpoint
app.use('/graphql', bodyParser.json(), graphqlExpress({ schema }));
// GraphiQL, a visual editor for queries
app.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql' }));
// Start the server
app.listen(3001, () => {
console.log('Go to http://localhost:3001/graphiql to run queries!');
});