Created
June 22, 2021 04:34
-
-
Save osha7/300f965fea7b7cad8c154187099caa39 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "reflect-metadata"; | |
import { MikroORM } from "@mikro-orm/core"; | |
import { __prod__ } from "./constants"; | |
import microConfig from "./mikro-orm.config"; | |
import express from "express"; | |
import { ApolloServer } from "apollo-server-express"; | |
import { buildSchema } from "type-graphql"; | |
import { HelloResolver } from "./resolvers/hello"; | |
import { PostResolver } from "./resolvers/post"; | |
const main = async () => { | |
const orm = await MikroORM.init(microConfig); | |
await orm.getMigrator().up(); | |
const app = express(); | |
const apolloServer = new ApolloServer({ | |
schema: await buildSchema({ | |
//graphql schema | |
resolvers: [HelloResolver, PostResolver], | |
validate: false, | |
}), | |
// need a function that returns an object for the context: | |
context: () => ({ em: orm.em }) //special object accessable by all the resolvers | |
}); | |
apolloServer.applyMiddleware({ app }); | |
app.listen(5000, () => { | |
console.log("server started on localhost: 5000"); | |
}); | |
}; | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment