This repository has been archived by the owner on Oct 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 161
/
Copy path.roadhogrc.mock.js
81 lines (75 loc) · 2.44 KB
/
.roadhogrc.mock.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import fs from 'fs';
import { delay } from 'roadhog-api-doc';
import { getGlobalTopology, getServiceTopology, getEndpointTopology } from './mock/topology';
import { Alarms, AlarmTrend } from './mock/alarm';
import { TraceBrief, Trace } from './mock/trace'
import { getAllDatabases, getTopNRecords } from './mock/database'
import { makeExecutableSchema, addMockFunctionsToSchema } from 'graphql-tools';
import { graphql } from 'graphql';
import { ClusterBrief, getServiceInstances, getAllServices, searchEndpoint, EndpointInfo } from './mock/metadata';
import { IntValues, Thermodynamic } from './mock/metric';
import { getServiceTopN, getAllEndpointTopN, getServiceInstanceTopN, getEndpointTopN } from './mock/aggregation';
const noMock = process.env.NO_MOCK === 'true';
const resolvers = {
Query: {
getAllServices,
getAllDatabases,
getTopNRecords,
getServiceInstances,
getServiceTopN,
getAllEndpointTopN,
getGlobalTopology,
getServiceTopology,
getEndpointTopology,
searchEndpoint,
getEndpointTopN,
getServiceInstanceTopN,
}
}
const schema = makeExecutableSchema({ typeDefs: [
"scalar Long",
fs.readFileSync('query-protocol/common.graphqls', 'utf8'),
fs.readFileSync('query-protocol/metadata.graphqls', 'utf8'),
fs.readFileSync('query-protocol/top-n-records.graphqls', 'utf8'),
fs.readFileSync('query-protocol/alarm.graphqls', 'utf8'),
fs.readFileSync('query-protocol/metric.graphqls', 'utf8'),
fs.readFileSync('query-protocol/aggregation.graphqls', 'utf8'),
fs.readFileSync('query-protocol/trace.graphqls', 'utf8'),
fs.readFileSync('query-protocol/topology.graphqls', 'utf8'),
], resolvers });
addMockFunctionsToSchema({
schema,
mocks: {
Long: () => 1,
ClusterBrief,
Thermodynamic,
AlarmTrend,
Alarms,
TraceBrief,
Trace,
IntValues,
EndpointInfo,
},
preserveResolvers: true
});
const proxy = {
'POST /api/graphql': (req, res) => {
const { query: source, variables: variableValues } = req.body;
graphql({ schema, source, variableValues }).then((result) => res.send(result));
},
'POST /api/login/account': (req, res) => {
const { password, userName } = req.body;
if (password === '888888' && userName === 'admin') {
res.send({
status: 'ok',
currentAuthority: 'admin',
});
return;
}
res.send({
status: 'error',
currentAuthority: 'guest',
});
},
};
export default noMock ? {} : delay(proxy, 1000);