-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathserver.js
52 lines (44 loc) · 1.07 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
49
50
51
52
const express = require("express");
const bodyParser = require("body-parser");
const fetch = require("node-fetch");
const app = express();
const PORT = process.env.PORT || 3000;
app.use(bodyParser.json());
app.post("/getUser", async (req, res) => {
const QUERY = `mutation AddOrder($title: String!) {
insert_orders(objects: {title: $title}) {
returning {
id
title
}
}
}`;
console.log("reached here", req.body.session_variables);
const A = await fetch("http://localhost:8081/v1/graphql", {
method: "POST",
body: JSON.stringify({
query: QUERY,
variables: {
title: "From Action",
},
}),
headers: {
...req.body.session_variables,
"X-hasura-admin-secret": "myadminsecretkey",
},
});
const B = await A.json();
console.log(B);
return res.json({
uuid: req.body.input.uuid,
firstName: "Dmytro",
lastName: "Mezhenskyi",
});
});
app.post("/buyit", async (req, res) => {
console.log("req", req.body);
return res.json({
field1: "world",
});
});
app.listen(PORT);