A Laravel-based GraphQL API for managing todos with user authentication.
- Framework: Laravel 12
- GraphQL: Nuwave Lighthouse
- Authentication: Laravel Sanctum (Bearer tokens)
- Database: MySQL
- Frontend: Vite + Vue.js (optional, for development)
- User registration and login
- JWT-like token authentication via Sanctum
- CRUD operations for todos
- GraphQL pagination support
- Graceful error handling (returns null for not found objects)
- GraphiQL playground for testing
- API Documentation - Complete GraphQL API reference with examples
- PHP 8.2+
- Composer
- Node.js & npm
- MySQL
-
Clone the repository:
git clone <repository-url> cd todo-graphql
-
Install PHP dependencies:
composer install
-
Install Node dependencies:
npm install
-
Environment setup:
cp .env.example .env php artisan key:generate
-
Configure database in
.env:DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=todo_app DB_USERNAME=your_username DB_PASSWORD=your_password
-
Run migrations:
php artisan migrate
-
Seed test data (optional):
php artisan db:seed
-
Build assets:
npm run build
# Start Laravel server
php artisan serve
# Start Vite dev server (for frontend assets)
npm run dev
# Run both concurrently
composer run devAccess the GraphiQL interface at: http://localhost:8000/graphiql
# Run PHP tests
php artisan test
# Run with coverage
php artisan test --coverage# Run PHP CS Fixer
./vendor/bin/php-cs-fixer fix
# Run Pint (Laravel's code style)
./vendor/bin/pintapp/
├── GraphQL/
│ ├── Mutations/
│ │ ├── CreateTodo.php
│ │ ├── DeleteTodo.php
│ │ ├── Login.php
│ │ ├── Logout.php
│ │ ├── Register.php
│ │ └── UpdateTodo.php
│ └── Queries/
│ ├── Me.php
│ ├── TodoQuery.php
│ ├── Todos.php
│ └── UserQuery.php
├── Models/
│ ├── Todo.php
│ └── User.php
└── ...
config/
├── lighthouse.php
├── sanctum.php
└── ...
database/
├── migrations/
│ ├── ..._create_users_table.php
│ └── ..._create_todos_table.php
└── seeders/
└── DatabaseSeeder.php
graphql/
└── schema.graphql
routes/
└── web.php
tests/
└── Feature/
└── ExampleTest.php
The API uses Laravel Sanctum for token-based authentication:
- Register/Login to get a bearer token
- Include token in
Authorizationheader for protected operations - Logout to revoke the token
const headers = {
'Authorization': 'Bearer your_token_here',
'Content-Type': 'application/json'
};The schema is defined in graphql/schema.graphql and includes:
- Types: User, Todo, AuthPayload, Message
- Queries: me, todos, todo, user, users
- Mutations: register, login, logout, createTodo, updateTodo, deleteTodo
Key environment variables:
APP_NAME="Todo GraphQL API"
APP_ENV=local
APP_KEY=base64:your_app_key
APP_DEBUG=true
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=todo_app
DB_USERNAME=user
DB_PASSWORD=password
SANCTUM_STATEFUL_DOMAINS=localhost:3000- Set
APP_ENV=productionandAPP_DEBUG=false - Configure production database
- Run
php artisan config:cacheandphp artisan route:cache - Set up web server (Apache/Nginx) to serve
public/directory - Ensure proper permissions for
storage/andbootstrap/cache/
This project is licensed under the MIT License.