Skip to content

Instantly share code, notes, and snippets.

@kkratos
Created December 31, 2021 10:06
Show Gist options
  • Save kkratos/0a97521bc95dfb5dcb986f0f40df9b8b to your computer and use it in GitHub Desktop.
Save kkratos/0a97521bc95dfb5dcb986f0f40df9b8b to your computer and use it in GitHub Desktop.
import express, {Application} from "express";
import { ApolloServer } from "apollo-server-express";
import { typeDefs, resolvers } from "./graphql/index";
import { connectDatabase } from "./database";
const port = 3000;
const mount = async (app: Application) => {
const db = await connectDatabase();
const server = new ApolloServer({
typeDefs,
resolvers,
context:() => ({ db })
});
server.applyMiddleware({app, path:'/api'})
app.listen(port);
console.log(`[app]: http://localhost:${port}`);
const listings = await db.listings.find({}).toArray();
console.log(listings);
}
mount(express());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment