-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
43 lines (37 loc) · 991 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
31
32
33
34
35
36
37
38
39
40
41
42
43
import fs from "fs";
import express from "express";
import { MongoClient } from "mongodb";
import config from "./config";
// Graphql imports!
import { graphql } from "graphql";
import Schema from "./public/Data/schema";
import GraphQLHTTP from "express-graphql";
import { introspectionQuery } from "graphql/utilities";
const app = express();
let database;
app.use(express.static("public"));
(async () => {
const client = await MongoClient.connect(config.mongoUrl, {
useUnifiedTopology: true
});
const db = client.db("rgr");
const schema = Schema(db);
app.use(
"/graphql",
GraphQLHTTP({
schema
//graphiql: true
})
);
app.listen(3000, () => console.log("listening on port 3000"));
// Generate Schema.json
const json = await graphql(schema, introspectionQuery);
fs.writeFile(
"./public/Data/schema.json",
JSON.stringify(json, null, 2),
err => {
if (err) throw err;
console.log("Schema Generated!");
}
);
})();