-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
39 lines (33 loc) · 869 Bytes
/
server.js
File metadata and controls
39 lines (33 loc) · 869 Bytes
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
import express from 'express'
import { createHandler } from 'graphql-http/lib/use/express';
import { schema } from './schema.js';
import { ruruHTML } from "ruru/server"
const root = {
quoteOfTheDay() {
return Math.random() < 0.5 ? "Take it easy" : "Salvation lies within"
},
random() {
return Math.random()
},
rollDice({ numDice, numSides }) {
let output = []
for (let i = 0; i < numDice; i++) {
output.push(1 + Math.floor(Math.random() * (numSides || 6)))
}
return output
},
}
const app = express();
app.all(
'/graphql',
createHandler({
schema: schema,
rootValue: root,
})
);
app.get("/", (_req, res) => {
res.type("html")
res.end(ruruHTML({ endpoint: "/graphql" }))
})
app.listen({ port: 4000 });
console.log('Listening to port 4000');