How lisbooa16/django-with-graphql works
Project type and purpose
• This is a backend-only web API built with Django and Graphene (GraphQL).
• Its purpose is to expose “quiz” data (categories, quizzes, questions, answers) and user info through a GraphQL endpoint.
• It is not a full-stack application with a separate frontend; rather, it is an API service that clients (e.g. a React front-end or GraphiQL IDE) will consume.
File structure
Top-level files and directories:
• manage.py – Django CLI entry point
• core/ – project configuration (settings, URL routing, ASGI/WGI)
• books/, quiz/, users/ – three Django “apps,” each containing:
– models.py (Django ORM definitions)
– schema.py (Graphene schema definitions: types, queries, mutations)
– views.py (if any; Graphene typically uses one GraphQL view)
– urls.py (app-level routing if needed)
– migrations/ (database schema evolution)
• db.sqlite3 – development database
• requirements.txt – Python library versions
README for additional insights
• Confirms this is a Django + Graphene GraphQL API.
• Shows example queries and mutations (createCategory, updateCategory, allQuestions, allAnswers, me, users).
• Describes the domain models: Category → Quiz → Question → Answer, plus User.
• Notes use of GraphiQL at /graphql/ for interactive exploration.
Main components
a. Client(s)
• GraphiQL IDE (browser)
• Any external consumer (mobile app, web SPA, server-to-server)
b. API Server
• Django Core (core/asgi.py, core/wsgi.py)
• Django URL Router (core/urls.py → directs /graphql/)
• Graphene View (a single GraphQL endpoint, typically wired in core/urls.py)
c. Application Modules (apps)
• users: defines User model, user-related GraphQL types, queries, mutations
• quiz: defines Category, Quiz, Question, Answer models, their GraphQL types
• books: analogous structure (if used in demo)
d. Database
• SQLite (development) or configurable to PostgreSQL, MySQL, etc.
e. External/Infrastructure
• (Optional) Authentication service (if JWT or OAuth added)
• Hosting environment (Docker, AWS, Heroku, etc.)
Relationships and data flows
1. Client sends GraphQL request (query or mutation) over HTTP to /graphql/
2. Django URL resolver routes to the Graphene view
3. Graphene parses the request, invokes corresponding schema resolvers in each app’s schema.py
4. Resolvers call Django ORM methods on models (books.models, quiz.models, users.models)
5. ORM generates SQL, interacts with the database
6. Results bubble back up to Graphene, which serializes to JSON
7. HTTP response returns JSON payload to client
Architectural patterns and design principles
• Modular Django apps: each domain (users, quiz, books) is self-contained
• Single GraphQL endpoint vs REST: Graphene unifies queries and mutations
• ORM as data-access abstraction (Django models + migrations)
• Schema-first GraphQL design: clear separation of types, queries, and mutations in schema.py
• Loose coupling: clients know only GraphQL schema, not internal Django URL structure
Technologies, frameworks, and libraries
• Python 3.x, Django
• graphene-django (GraphQL integration)
• SQLite (or pluggable RDBMS)
• dependency list in requirements.txt