graphqlServer.js
7.67 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
var express = require('express');
var { graphqlHTTP } = require('express-graphql');
var { buildSchema } = require('graphql');
// Construct a schema, using GraphQL schema language
var schema = buildSchema(`
type apiList {
api: String
}
type Query {
apiList: [apiList]
}
`);
// The root provides a resolver function for each API endpoint
var data = {
"apiList": [{
"api": "hello"
}],
"resultCode": "20000",
"resultDescription": "Success"
};
const extensions = ({
document,
variables,
operationName,
result,
context,
}) => {
return {
resultCode: "20000",
resultDescription: "success"
};
};
var app = express();
// app.use('/graphql', graphqlHTTP({
// schema: schema,
// // rootValue: data,
// graphiql: true,
// extensions
// }));
app.use('/graphql', (req, res) => {
console.log(req.body)
res.status(200).send({
"data": {
"apiList": [{
"api": {
"_id": "635a05d5bc7f8b9de2595311",
"method": "GET",
"uri": "/api/v1/resource",
"description": "URI Description",
"exRequest": {
"header": [{
"paramName": "test1",
"isRequire": "1",
"dataType": "String",
"description": "test1"
}, {
"paramName": "test2",
"isRequire": "0",
"dataType": "Object",
"description": "test2.1",
"paramObj": [{
"paramName": "test2.1",
"isRequire": "0",
"dataType": "Object",
"description": "test2.1",
"paramObjParamObj": [{
"paramName": "test2.1.1",
"isRequire": "0",
"dataType": "Number",
"description": "test2.1.1"
}
]
}
]
}
],
"exHeader": [{
"text": "Request Header Example"
}
],
"body": [{
"paramName": "test1",
"isRequire": "1",
"dataType": "String",
"description": "test1"
}, {
"paramName": "test2",
"isRequire": "0",
"dataType": "String",
"description": "test2"
}
],
"exBody": [{
"text": "Request Body Example"
}
]
},
"exResponse": {
"header": [{
"paramName": "test1",
"isRequire": "1",
"dataType": "String",
"description": "test1"
}
],
"exHeader": [{
"text": "Response Header Example (Success)"
}
],
"exHeaderErr": [{
"text": "Response Header Example (Error)"
}
],
"body": [{
"paramName": "test1",
"isRequire": "0",
"dataType": "String",
"description": "test1"
}, {
"paramName": "test2",
"isRequire": "1",
"dataType": "String",
"description": "test2"
}, {
"paramName": "test3",
"isRequire": "1",
"dataType": "Object",
"description": "test3",
"paramObj": [{
"paramName": "test3.1",
"isRequire": "1",
"dataType": "Number",
"description": "test3.1"
}, {
"paramName": "test3.2",
"isRequire": "0",
"dataType": "Integer",
"description": "test3.2"
}
]
}
],
"exBody": [{
"text": "Response Body Example (Success)"
}
],
"exBodyNoData": [{
"text": "Response Body Example (Success no data)"
}
],
"exBodyErr": [{
"text": "Response Body Example (Error)"
}
]
},
"customParams": [{
"customKey": "Custom Parameter key",
"customValue": "Custom Parameter value"
}, {
"customKey": "Custom Parameter key 2",
"customValue": "Custom Parameter value 2"
}
]
},
"resource": {
"_id": "635a05d5bc7f8b51b3595310",
"resourceName": "Resource Name",
"resourceOwner": "supps305",
"systemName": "System Name",
"status": "Approved"
},
"microservicesDomain": {
"_id": "635a05d5bc7f8bf46b59530d",
"microservicesDomainName": "Microservices Domain",
"description": "Microservices Domain Description"
}
}
]
},
"resultCode": "40101",
"resultDescription": "Success"
})
})
app.listen(4000);
console.log('Running a GraphQL API server at http://localhost:4000/graphql');