-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
49 lines (42 loc) · 1.38 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const express = require('express');
// const schema = require('./schema/manualSchema');
// const schema = require('./schema/mongoDbPoweredSchema');
const schema = require('./schema/graphQLToMongoDbSchema');
//var graphQLHTTP = require('express-graphql');
const {ApolloServer, makeExecutableSchema} = require('apollo-server-express');
const mongodb = require('mongodb');
const assert = require('assert');
//const CustomApolloServer = require('./apollo/customApolloServer');
(async () => {
const MongoClient = mongodb.MongoClient;
const mongoUrl = 'mongodb://localhost:27017';
let db;
try {
let client = await MongoClient.connect(mongoUrl);
db = client.db('graphQLTest');
} catch (error) {
console.error(error);
process.exit(1);
}
// single-tenant, but fancier way
const app = express();
const port = 4001 || process.env;
const server = new ApolloServer({
schema,
context: {db: db},
playground: {
endpoint: `http://localhost:${port}/graphql`,
settings: {
'editor.theme': 'dark',
'editor.cursorShape': 'line',
}
}
});
server.applyMiddleware({
app: app
});
app.listen(port, () => {
console.log(`The server has started on port: ${port}`);
console.log(`http://localhost:${port}/graphql`);
});
})();