A comprehensive Python backend application using Flask, SQLAlchemy, and Graphene to demonstrate GraphQL with CRUD functionality, authentication, rate limiting, and more.
- GraphQL API: Perform CRUD operations on books and users.
- Authentication: Secure user registration and login using password hashing.
- Social Authentication: Allow users to log in using third-party services.
- Rate Limiting: Limit the number of API requests per IP to prevent abuse.
- Notifications: Send and manage user notifications.
- Password Reset: Generate tokens for password reset functionality.
- Email Service: Utility to send emails (e.g., for password reset).
- Validators: Utility functions to validate email and password formats.
- Helpers: Utility functions for common tasks like generating random strings.
-
Clone the repository:
git clone https://github.com/your-repo-link/graphql-flask-backend.git cd graphql-flask-backend
-
Set up a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
-
Install the required packages:
pip install -r requirements.txt
- Book: Contains fields like
id
,title
, andauthor
. - User: Contains fields like
id
,username
,email
, androle
. - Notification: Manages user notifications.
- APIRateLimit: Tracks and enforces rate limits for different IP addresses.
- UserSocialAuth: Stores authentication details for third-party services.
- PasswordResetToken: Manages tokens for password reset functionality.
Refer to the individual GraphQL files for detailed operations, including creating, updating, deleting, and querying books and users.
/graphql
: The main GraphQL endpoint. Use this to perform all CRUD operations. You can also access the GraphiQL interface here for testing and documentation.
-
Set up the database:
flask db init flask db migrate flask db upgrade
-
Execute the Python script:
python run.py
-
Visit: Open
http://localhost:5000/graphql
in your browser to access the GraphiQL interface and test the CRUD operations.
Tests are located in the tests/
directory. To run them, use:
pytest
- Fork the repository.
- Create a new branch for your features or bug fixes.
- Commit your changes and push to your fork.
- Open a pull request from your fork to the main repository.
This project is licensed under the MIT License. See the LICENSE
file for details.