BookQL is a GraphQL-based API project built using Django and Strawberry GraphQL. This project provides CRUD operations on books through queries and mutations, utilizing session-based authentication.
- GraphQL API: Perform CRUD operations on books using GraphQL queries and mutations.
- Django Integration: Built on top of Django, leveraging its ORM and authentication system.
- Session-Based Authentication: Uses Django's session-based authentication to secure the API.
- Schema and Types: Includes GraphQL schema, Strawberry Django types, and input definitions for managing books.
- Python 3.x
- Django 3.x or higher
- Strawberry GraphQL
-
Clone the repository:
git clone https://github.com/samikshakhadka/BookQL.git cd BookQL
-
Create and activate a virtual environment:
python3 -m venv venv source venv/bin/activate
-
Install the required dependencies:
pip install -r requirements.txt
-
Run database migrations:
python manage.py migrate
-
Create a superuser (optional, for accessing the Django admin panel):
python manage.py createsuperuser
-
Run the development server:
python manage.py runserver
Once the development server is running, you can access the GraphQL API by navigating to:
http://localhost:8000/graphql/
You can perform CRUD operations on books using the following GraphQL queries and mutations:
-
Create a Book:
mutation { createBook(input: { title: "New Book", author: "Author Name", description: "Book Description" }) { book { id title author description } } }
-
Retrieve a Book:
query { book(id: 1) { id title author description } }
-
Update a Book:
mutation { updateBook(id: 1, input: { title: "Updated Title" }) { book { id title author description } } }
-
Delete a Book:
mutation { deleteBook(id: 1) { success message } }
BookQL uses session-based authentication. Ensure that you are logged in before performing mutations. You can log in via the Django admin panel or through a custom login mutation if implemented.
The project includes the following key components:
- Schema: Defines the available queries and mutations.
- Types: Defines the Django models that are exposed via the API using Strawberry's
@strawberry.django.type
. - Inputs: Defines the input types for creating and updating books.
Contributions are welcome! Please fork the repository, create a new branch, and submit a pull request with your changes.