-
-
Notifications
You must be signed in to change notification settings - Fork 677
/
index.ts
29 lines (24 loc) · 916 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
import "reflect-metadata";
import { ApolloServer } from "@apollo/server";
import { startStandaloneServer } from "@apollo/server/standalone";
import { Container } from "typedi";
import { buildSchema } from "type-graphql";
import { RecipeResolver } from "./recipe.resolver";
import { sampleRecipes } from "./recipe.data";
// Add sample recipes in container
Container.set({ id: "SAMPLE_RECIPES", factory: () => sampleRecipes.slice() });
async function bootstrap() {
// Build TypeGraphQL executable schema
const schema = await buildSchema({
// Array of resolvers
resolvers: [RecipeResolver],
// Registry 3rd party IOC container
container: Container,
});
// Create GraphQL server
const server = new ApolloServer({ schema });
// Start server
const { url } = await startStandaloneServer(server, { listen: { port: 4000 } });
console.log(`GraphQL server ready at ${url}`);
}
bootstrap();