|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Lighthouse is a GraphQL framework for Laravel that uses a schema-first approach with directives. |
| 8 | +It integrates `webonyx/graphql-php` with Laravel's ecosystem. |
| 9 | + |
| 10 | +## Development Commands |
| 11 | + |
| 12 | +The project uses Docker + Make for a reproducible development environment. |
| 13 | + |
| 14 | +```bash |
| 15 | +make setup # Initial setup: build containers, install dependencies |
| 16 | +make # Run all checks before committing (fix, stan, test) |
| 17 | +make fix # Auto-format code (rector, php-cs-fixer, prettier) |
| 18 | +make stan # Static analysis with PHPStan |
| 19 | +make test # Run PHPUnit tests |
| 20 | +make bench # Run PHPBench benchmarks |
| 21 | +make php # Shell into PHP container |
| 22 | +``` |
| 23 | + |
| 24 | +### Running a Single Test |
| 25 | + |
| 26 | +```bash |
| 27 | +docker-compose exec php vendor/bin/phpunit --filter=TestClassName |
| 28 | +docker-compose exec php vendor/bin/phpunit --filter=testMethodName |
| 29 | +docker-compose exec php vendor/bin/phpunit tests/Unit/Path/To/TestFile.php |
| 30 | +``` |
| 31 | + |
| 32 | +## Architecture |
| 33 | + |
| 34 | +### Entry Points |
| 35 | + |
| 36 | +- `src/LighthouseServiceProvider.php` - Main service provider, registers singletons and bindings |
| 37 | +- `src/GraphQL.php` - Main entrypoint to GraphQL execution (`@api` marked) |
| 38 | +- `src/Http/routes.php` - GraphQL endpoint routing |
| 39 | + |
| 40 | +### Schema Processing Pipeline |
| 41 | + |
| 42 | +1. **Schema Source** (`src/Schema/Source/`) - `SchemaStitcher` loads and combines `.graphql` files |
| 43 | +2. **AST Building** (`src/Schema/AST/`) - `ASTBuilder` parses schema into AST nodes |
| 44 | +3. **Schema Building** (`src/Schema/SchemaBuilder.php`) - Builds executable GraphQL schema |
| 45 | +4. **Type Registry** (`src/Schema/TypeRegistry.php`) - Manages GraphQL types |
| 46 | + |
| 47 | +### Directive System |
| 48 | + |
| 49 | +Directives are the core extension mechanism. Located in `src/Schema/Directives/`. |
| 50 | + |
| 51 | +- `BaseDirective` - Abstract base class for all directives, provides common utilities |
| 52 | +- Directive interfaces in `src/Support/Contracts/` define capabilities: |
| 53 | + - `FieldResolver` - Resolves field values |
| 54 | + - `FieldMiddleware` - Wraps field resolution |
| 55 | + - `ArgTransformerDirective` - Transforms argument values |
| 56 | + - `ArgBuilderDirective` - Modifies query builder |
| 57 | + - `TypeManipulator`, `FieldManipulator`, `ArgManipulator` - Schema manipulation |
| 58 | + |
| 59 | +Directives are named by convention: `FooDirective` maps to `@foo` in GraphQL schema. |
| 60 | + |
| 61 | +### Service Providers |
| 62 | + |
| 63 | +Multiple service providers for optional features (auto-discovered via composer.json): |
| 64 | +- `AuthServiceProvider` - Authentication directives (@auth, @can, @guard) |
| 65 | +- `CacheServiceProvider` - Query result caching (@cache) |
| 66 | +- `PaginationServiceProvider` - Pagination types and directives |
| 67 | +- `ValidationServiceProvider` - Input validation (@rules) |
| 68 | +- `SoftDeletesServiceProvider`, `GlobalIdServiceProvider`, `OrderByServiceProvider` |
| 69 | + |
| 70 | +### Testing Infrastructure |
| 71 | + |
| 72 | +- `tests/TestCase.php` - Base test class using Orchestra Testbench |
| 73 | +- `tests/DBTestCase.php` - Tests requiring database (MySQL) |
| 74 | +- `MakesGraphQLRequests` trait - `$this->graphQL($query)` helper for testing |
| 75 | +- `MocksResolvers` trait - Mock field resolvers |
| 76 | +- `UsesTestSchema` trait - Set schema via `$this->schema = '...'` |
| 77 | + |
| 78 | +Tests use `Tests\Utils\` namespace for test fixtures (Models, Queries, Mutations, etc.). |
| 79 | + |
| 80 | +## Code Style |
| 81 | + |
| 82 | +- PHPStan level 8 |
| 83 | +- php-cs-fixer with `mll-lab/php-cs-fixer-config` (risky rules) |
| 84 | +- `protected` over `private` for extensibility |
| 85 | +- Never use `final` in `src/`, always in `tests/` |
| 86 | +- Full namespace in PHPDoc (`@var \Full\Namespace\Class`), imports in code |
| 87 | +- Code elements with `@api` have stability guarantees between major versions |
0 commit comments