-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
33 lines (26 loc) · 942 Bytes
/
app.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
31
32
33
import express from 'express';
import bodyParser from 'body-parser';
import { graphqlExpress, graphiqlExpress } from 'apollo-server-express';
import { makeExecutableSchema } from 'graphql-tools';
import mongoose from 'mongoose';
import fs from 'fs';
import resolvers from './src/resolvers';
import mongooseSchema from './src/database/mongooseSchema';
const app = express();
mongoose.connect('mongodb://localhost:27017/graphqldb');
const typeDefs = fs.readFileSync('./src/database/typeDefs.graphql', 'utf8');
const schema = makeExecutableSchema({
typeDefs,
resolvers,
});
// The GraphQL endpoint
app.use('/graphql', bodyParser.json(), graphqlExpress({
schema,
context: mongooseSchema
}));
// GraphiQL, a visual editor for queries
app.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql' }));
// Start the server
app.listen(3000, () => {
console.log('Go to http://localhost:3000/graphiql to run queries!');
});