|
| 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 | +Laravel package providing a GraphQL client for Shopify's Admin API, built on Saloon HTTP client. |
| 8 | + |
| 9 | +## Commands |
| 10 | + |
| 11 | +```bash |
| 12 | +composer test # Run tests (Pest) |
| 13 | +composer analyse # Run PHPStan (level 9) |
| 14 | +composer format # Run Laravel Pint |
| 15 | +``` |
| 16 | + |
| 17 | +Run a single test: |
| 18 | +```bash |
| 19 | +./vendor/bin/pest tests/ExampleTest.php |
| 20 | +./vendor/bin/pest --filter="test name" |
| 21 | +``` |
| 22 | + |
| 23 | +## Architecture |
| 24 | + |
| 25 | +### Client Flow |
| 26 | + |
| 27 | +1. `GraphQLClient::factory()` returns `GraphQLClientCreate` |
| 28 | +2. `GraphQLClientCreate::create($authenticator)` returns `GraphQLClientMethods` |
| 29 | +3. `GraphQLClientMethods` provides the API: `query()`, `mutate()`, bulk operations |
| 30 | + |
| 31 | +### Key Components |
| 32 | + |
| 33 | +**Core Classes** (`src/`): |
| 34 | +- `GraphQLClientMethods`: Main API facade with `query()`, `mutate()`, and bulk operation methods |
| 35 | +- `GraphQLClientTransformer`: Response wrapper with `toArray()`, `toCollection()`, `toDTO()` methods |
| 36 | + |
| 37 | +**Services** (`src/Services/`): |
| 38 | +- `RequestExecutor`: Centralized request handling with rate limit tracking and retry logic |
| 39 | +- `ThrottleDetector`: Detects Shopify API throttling from responses |
| 40 | +- `RedisRateLimitService` / `NullRateLimitService`: Rate limit tracking implementations |
| 41 | +- `QueryTransformer`: GraphQL query pagination transformation |
| 42 | + |
| 43 | +**Contracts** (`src/Contracts/`): |
| 44 | +- `RateLimitable`: Interface for rate limit services |
| 45 | +- `ThrottleDetectable`: Interface for throttle detection |
| 46 | + |
| 47 | +**Data Objects** (`src/Data/`): |
| 48 | +- `RateLimitState`: Immutable value object for rate limit information |
| 49 | + |
| 50 | +**Enums** (`src/Enums/`): |
| 51 | +- `ResponsePath`: Maps response types to their data extraction paths |
| 52 | +- `GraphQLRequestType`: Query vs Mutation type |
| 53 | + |
| 54 | +**GraphQL** (`src/GraphQL/`): |
| 55 | +- `BulkOperationQueries`: Centralized GraphQL query templates for bulk operations |
| 56 | + |
| 57 | +**Integrations** (`src/Integrations/`): |
| 58 | +- `ShopifyConnector`: Saloon connector handling base URL, auth, and failure detection |
| 59 | +- `Requests/`: Saloon request classes (Query, Mutation, BulkOperation, etc.) |
| 60 | + |
| 61 | +**Authenticators** (`src/Authenticators/`): |
| 62 | +- `ShopifyApp`: Handles shop domain and access token validation |
| 63 | + |
| 64 | +### Design Patterns |
| 65 | + |
| 66 | +- **Factory pattern**: `GraphQLClient::factory()->create($authenticator)` |
| 67 | +- **Value objects**: `RateLimitState` for immutable rate limit data |
| 68 | +- **Strategy pattern**: `RateLimitable` and `ThrottleDetectable` contracts allow swapping implementations |
| 69 | +- **Template method**: Request classes extend `BaseRequest` with `defaultBody()` implementation |
| 70 | + |
| 71 | +## Configuration |
| 72 | + |
| 73 | +Published to `config/shopify-graphql.php`: |
| 74 | +- `api_version`: Shopify API version (default: 2025-01) |
| 75 | +- `fail_on_throttled`: Whether to fail immediately on throttle (default: true) |
| 76 | +- `throttle_max_tries`: Retry attempts before failing (default: 5) |
| 77 | + |
| 78 | +## Testing |
| 79 | + |
| 80 | +Uses Pest with Orchestra Testbench. Tests extend `TestCase` which registers the service provider. |
0 commit comments