Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 152 additions & 1 deletion backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"type": "module",
"dependencies": {
"@apollo/server": "^5.5.1",
"graphql": "^16.14.2"
"graphql": "^16.14.2",
"mongodb": "^7.7.0"
},
"devDependencies": {
"@types/node": "^26.6.5",
Expand Down
13 changes: 13 additions & 0 deletions backend/src/db.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { MongoClient } from "mongodb";

const uri = process.env.MONGODB_URI ?? "mongodb://127.0.0.1:27017";

const client = new MongoClient(uri);

export async function connectToDatabase() {
await client.connect();

console.log("Connected to MongoDB");

return client.db("artex");
}
4 changes: 4 additions & 0 deletions backend/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ApolloServer } from "@apollo/server";
import { startStandaloneServer } from "@apollo/server/standalone";
import { connectToDatabase } from "./db.js";

// Define the GraphQL schema
const typeDefs = `#graphql
Expand All @@ -15,6 +16,9 @@ const resolvers = {
},
};

// Connect to MongoDB before starting the server
await connectToDatabase();

// Create the Apollo Server
const server = new ApolloServer({
typeDefs,
Expand Down