require ( 'dotenv-safe' ) . config ( ) ; import 'reflect-metadata' ; import { buildSchema } from 'type-graphql' ; import { Container } from 'typedi' ; import * as typeorm from 'typeorm' ; import { ApolloError , ApolloServer } from 'apollo-server-express' ; import * as express from 'express' ; import * as cors from 'cors' ; typeorm . useContainer ( Container ) ; async function bootstrap ( ) { const conn = await typeorm . createConnection ( ) ; await conn . synchronize ( ) ; const app = express ( ) ; app . use ( cors ( { credentials : true , origin : 'http://localhost:3000' } ) ) ; const schema = await buildSchema ( { resolvers : [ __dirname + '/modules/**/resolver.*' ] , emitSchemaFile : __dirname + '/schema.graphql' , container : Container , validate : false } ) ; const server = new ApolloServer ( { schema , context : ( { req } ) => ( { req } ) } ) ; server . applyMiddleware ( { app , cors : false } ) ; app . listen ( { port : 4000 } , ( ) => console . log ( `🚀 Server ready at http://localhost:4000${ server . graphqlPath }` ) ) ; } bootstrap ( ) ;