nuwave/lighthouse
Lighthouse is a Laravel-first GraphQL server framework. Define your schema, wire resolvers, and handle common tasks like validation, auth, pagination, and Eloquent integration, with flexibility for custom GraphQL needs.
BuildSchemaString) and native PHP types for edge cases (e.g., enums, scalars), enabling hybrid development.@model directives.@skip, @include, custom directives).| Risk Area | Mitigation Strategy |
|---|---|
| Schema Drift | Use Lighthouse’s schema validation and CI checks (e.g., graphql-php schema validation). |
| Performance Bottlenecks | Profile with Lighthouse’s built-in metrics and Laravel’s debugbar. Optimize resolvers with caching (e.g., @cache). |
| Complex Resolvers | Leverage Laravel’s service layer to decouple business logic from GraphQL resolvers. |
| Migration from REST | Use Lighthouse’s @rest directive to gradually expose GraphQL endpoints alongside REST. |
| Custom Directives | Test client directives thoroughly; use ResolveInfo for edge cases (e.g., multi-node directives). |
VerifyCsrfToken for file uploads).@cache directive).| Phase | Action Items |
|---|---|
| Assessment | Audit existing REST endpoints; identify candidates for GraphQL replacement. |
| Pilot | Migrate one domain (e.g., Users API) using @model directives. |
| Hybrid Mode | Use @rest directives to expose GraphQL alongside REST (gradual rollout). |
| Full Adoption | Deprecate REST endpoints; enforce GraphQL for new features. |
| Optimization | Profile with tntsearch/graphql-php tools; optimize resolvers. |
composer require nuwave/lighthouse.php artisan lighthouse:install.graphql/schema.graphql).User, Post).@model for Eloquent mappings.app/GraphQL/Queries/GetUser.php).UserRepository).auth:sanctum)./graphql.debugbar or third-party tools.graphql-php schema checks).nuwave/lighthouse for major version updates (SemVer compliance).composer.json for stability.dd() or debugbar for resolver debugging.@skip behavior).@cache directives for frequent queries.@paginate or custom directives.| Failure Scenario | Mitigation |
|---|---|
| Schema Errors | Validate schema in CI; use @deprecated for safe transitions. |
| Resolver Crashes | Wrap resolvers in try-catch; log errors to Sentry/Laravel logs. |
| Authentication Bypass | Enforce middleware (e.g., auth:sanctum) on all queries/mutations. |
| File Upload Attacks | Validate file types/sizes in resolvers; use Laravel’s validate() rules. |
| Query Depth Attacks | Set max query depth in Lighthouse config (max_query_depth). |
| Database Timeouts | Use queue workers for long-running resolvers (e.g., Horizon). |
php artisan lighthouse:generateHow can I help you explore Laravel packages today?