This is a boilerplate application built with FastAPI, Strawberry GraphQL, and MongoDB. It provides a starting point for building a FastAPI application that uses GraphQL as the API layer and MongoDB as the backend database.
- Integration of FastAPI and Strawberry GraphQL.
- MongoDB integration for data storage.
- Example implementation of GraphQL queries and mutations.
- Boilerplate code for handling MongoDB operations.
- Python 3.8 or above
- MongoDB installed and running on your machine
-
Clone the repository:
git clone origin [email protected]:balumn/fastapi-strawberry-mongodb.git
-
Change to the project directory:
cd fastapi-strawberry-mongodb/
-
Create a virtual environment:
python3 -m venv venv
-
Activate the virtual environment:
-
For Linux/Mac:
source venv/bin/activate
-
For Windows (Command Prompt):
.\venv\Scripts\activate.bat
-
For Windows (PowerShell):
.\venv\Scripts\Activate.ps1
-
-
Install the dependencies:
pip install -r requirements.txt
-
Set up your MongoDB connection:
-
Update the MongoDB connection string in
app/db.py
:client = MongoClient("mongodb://localhost:27017")
-
Modify the database name in
app/db.py
:db = client["mydatabase"]
- Run the application:
uvicorn main:app --reload
The application will be accessible at http://localhost:8000
.
- Open the GraphiQL interface to explore and test the GraphQL API:
Visit http://localhost:8000/graphql
in your browser.
-
Example queries/mutations to try:
-
Get all users:
query {
all_users {
name
photoUrl
emailId
mobile
createdOn
updatedOn
}
}
- Create a user:
mutation {
create_user(userInput: {
name: "John Doe",
photoUrl: "https://example.com/photo.jpg",
emailId: "[email protected]",
mobile: "1234567890"
}) {
name
photoUrl
emailId
mobile
createdOn
updatedOn
}
}
- Customize the GraphQL schema, resolvers, and MongoDB operations according to your application requirements.
Contributions are welcome! If you find any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request.
This project is licensed under the MIT License.