-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
33 lines (29 loc) · 918 Bytes
/
main.js
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
require("dotenv").config();
const { ApolloServer } = require("@apollo/server");
const { startStandaloneServer } = require("@apollo/server/standalone");
const typeDefs = require("./graphql/type-defs");
const resolvers = require("./graphql/resolvers");
const { default: mongoose } = require("mongoose");
const server = new ApolloServer({
typeDefs,
resolvers,
});
const connectMongoDB = async () => {
try {
const url = process.env.MONGODB_URL || "";
mongoose.set("strictQuery", false);
await mongoose.connect(url);
} catch (error) {
throw new Error(`Failed connect to MongoDB: ${String(error)}`);
}
};
const main = async () => {
try {
await connectMongoDB();
const { url } = await startStandaloneServer(server);
console.log(`🚀 Server ready at ${url}`);
} catch (error) {
console.error(new Date(), error);
}
};
main();