-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
42 lines (35 loc) · 1021 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
const express = require('express');
const express_graphql = require('express-graphql');
const { buildSchema } = require('graphql');
const cors = require('cors');
const { createDb, getSegmentsData } = require('./server/sqliteWrapper');
// GraphQL schema
const schema = buildSchema(`
type Query {
segment(id: Int!): Segment
segments: [Segment]
},
type Segment {
id: Int
source: String
target: String
}
`);
let getSegments;
let getSegment = ({ id }) => getSegments.filter(seg => seg.id == id)[0];
getSegmentsData('Hagakure', (res) => {
console.log(res.dataValues.segments)
getSegments = JSON.parse(res.dataValues.segments);
const root = {
segment: getSegment,
segments: getSegments,
};
const app = express();
app.use(cors());
app.use('/graphql', express_graphql({
schema: schema,
rootValue: root,
graphiql: false
}));
app.listen(3333, () => console.log('Express GraphQL Server Now Running On localhost:3333/graphql'));
});