Build a createMeal GraphQL mutation for the ourHavenAPI Laravel backend using our architectural approach: GraphQL → Resolver → Facade → Service → Eloquent Model, with input validation and event-based notification.
This task tests your ability to work with Laravel, GraphQL via Lighthouse, and service-oriented design.
This project uses:
- Laravel (PHP framework)
- Lighthouse (GraphQL server for Laravel) 👉 Lighthouse Docs – Installation
- Eloquent ORM
- Laravel Events & Listeners
- GraphQL-first API (no REST endpoints)
You’ll be working entirely through the GraphQL layer.
-
GraphQL Mutation Add a
createMealmutation that accepts required fields and returns the created meal. -
Input Validation Use Lighthouse’s custom validator feature to enforce rules (e.g. required fields, value ranges, etc.).
-
Mutation Resolver Implement a class-based resolver that accepts input and passes it to a Facade.
-
Business Logic Layer Route logic through a Facade to a Service that handles model creation.
-
Model Interaction Create and persist a new Meal record using Laravel’s Eloquent model.
-
Event Handling After creation, fire a Laravel event to signal that a meal was created. Optionally, implement a listener for further side effects (e.g., notification or logging).
You’ll be working with a meals table. Assume the following structure:
| Field | Type | Notes |
|---|---|---|
| id | UUID/Int | Primary key |
| name | String | Required |
| description | Text | Optional |
| price | Decimal | Required, positive value |
| category_id | UUID/Int | Foreign key (optional) |
| created_at | Timestamp | Auto-managed by Laravel |
| updated_at | Timestamp | Auto-managed by Laravel |
You can include related models like MealCategory if needed.
- Client Mutation Call: Sends a GraphQL mutation with input
- Resolver: Handles input and invokes the Facade
- Facade: Delegates to a Service
- Service: Handles validation, creation, and fires an event
- Eloquent Model: Saves the meal in the database
- Event: Signals that a new meal was created
- Add a feature test to confirm mutation behavior
- Implement a listener that logs or sends an email on meal creation
- Use database seeding to simulate sample data
- Clone ourHaven Test repository
- Create a new branch for your solution
- Push your changes
- Make a PR to main branch
- Proper use of Laravel & Lighthouse features
- Clean architecture: GraphQL → Resolver → Facade → Service → Model
- Adherence to Laravel coding standards
- Modular, readable, and maintainable code
- Correct database interaction and event handling