-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
51 lines (42 loc) · 1.01 KB
/
app.ts
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
import express from 'express';
import expressGraphQL from 'express-graphql';
import { schema, createSDL } from './src/schema';
import { useSofa, OpenAPI } from 'sofa-api';
import bodyParser from 'body-parser';
import * as swaggerUi from 'swagger-ui-express';
import * as swaggerDocument from './swagger.json';
const app = express();
const PORT = 5000;
const openApi = OpenAPI({
schema,
info: {
title: 'Example API',
version: '3.0.0',
},
});
app.use(bodyParser.json());
app.use(
'/graphql',
expressGraphQL({
graphiql: true,
schema,
}),
);
app.use(
'/api',
useSofa({
schema,
onRoute(info) {
openApi.addRoute(info, {
basePath: '/api',
});
},
}),
);
openApi.save('./swagger.json');
openApi.save('./swagger.yml');
app.use('/', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
createSDL();
app.listen(PORT, () => {
console.log(`GrapiQL Server Running on http://localhost:${PORT}/graphql`);
});