-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
58 lines (48 loc) · 1.5 KB
/
index.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
53
54
55
56
57
58
const { diff } = require('@graphql-inspector/core');
const { loadSchema } = require('@graphql-tools/load');
const { UrlLoader } = require('@graphql-tools/url-loader');
const { express: voyagerMiddleware } = require('graphql-voyager/middleware');
const express = require('express');
const { createProxyMiddleware } = require('http-proxy-middleware');
const fs = require('fs');
const app = express();
app.get('/', (req, res) => {
res.send(fs.readFileSync('./index.html').toString());
});
const oldURL = process.argv.slice(2)[0];
const newURL = process.argv.slice(2)[1];
app.get('/diff', async (req, res) => {
const oldSchema = await loadSchema(oldURL, {
loaders: [
new UrlLoader(),
],
});
const newSchema = await loadSchema(newURL, {
loaders: [
new UrlLoader(),
],
});
const difference = diff(oldSchema, newSchema);
difference.sort((a, b) => {
if (a.path < b.path) {
return -1;
}
if (a.path > b.path) {
return 1;
}
return 0;
});
res.send(difference);
});
app.use('/graphql/old', createProxyMiddleware({
target: oldURL
}));
app.use('/graphql/new', createProxyMiddleware({
target: newURL
}));
app.use('/voyager/old', voyagerMiddleware({ endpointUrl: '/graphql/old' }));
app.use('/voyager/new', voyagerMiddleware({ endpointUrl: '/graphql/new' }));
const port = 5000;
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
});