forked from graphql-hive/graphql-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
28 lines (24 loc) · 755 Bytes
/
index.ts
File metadata and controls
28 lines (24 loc) · 755 Bytes
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
import 'reflect-metadata';
import { createApplication } from 'graphql-modules';
import { BlogModule } from './modules/blog';
import { UserModule } from './modules/user';
import http from 'http';
import { createHandler } from 'graphql-http/lib/use/http';
const app = createApplication({
modules: [BlogModule, UserModule],
});
// Create the GraphQL over HTTP Node request handler
const handler = createHandler({
schema: app.schema,
execute: app.createExecution(),
});
// Create a HTTP server using the listener on `/graphql`
const server = http.createServer((req, res) => {
if (req.url?.startsWith('/graphql')) {
handler(req, res);
} else {
res.writeHead(404).end();
}
});
server.listen(4000);
console.log('Listening to port 4000');