-
-
Notifications
You must be signed in to change notification settings - Fork 675
/
Copy pathindex.ts
35 lines (30 loc) · 975 Bytes
/
index.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
import "reflect-metadata";
import http from "node:http";
import path from "node:path";
import { createYoga } from "graphql-yoga";
import { buildSchema } from "type-graphql";
import { NotificationResolver } from "./notification.resolver";
import { pubSub } from "./pubsub";
async function bootstrap() {
// Build TypeGraphQL executable schema
const schema = await buildSchema({
// Array of resolvers
resolvers: [NotificationResolver],
// Create 'schema.graphql' file with schema definition in current directory
emitSchemaFile: path.resolve(__dirname, "schema.graphql"),
// Publish/Subscribe
pubSub,
});
// Create GraphQL server
const yoga = createYoga({
schema,
graphqlEndpoint: "/graphql",
});
// Create server
const httpServer = http.createServer(yoga);
// Start server
httpServer.listen(4000, () => {
console.log(`GraphQL server ready at http://localhost:4000/graphql`);
});
}
bootstrap().catch(console.error);