The example application
The example/ directory of the repository holds a complete Laravel application — a small "team blog" API of organizations, their members and the posts they publish. It is the reference the whole guide is built on: almost every code sample in these pages comes from it, and its test suite runs against this repository's own code (Composer installs Laragraph from the parent directory via a path repository), so anything the guide shows is known to work with the version you're reading about.
Run it
Requires PHP 8.3+ and Composer. From the repository root:
cd example
composer install
cp .env.example .env
php artisan key:generate
php artisan jwt:secret
touch database/database.sqlite
php artisan migrate --seed
php artisan serveThen open http://localhost:8000/graphql/graphiql in your browser (served because APP_DEBUG=true; see The HTTP API for what the IDE adds on top — auto-auth and the dev-only role/token picker).
Seeded accounts (password password):
| Role | |
|---|---|
admin@example.com | Admin of "Acme Corporation" |
member@example.com | Member of "Acme Corporation" |
Log in and keep the token, then try a query that touches several features at once — the me relation chain, a Relay connection, and a union search:
mutation {
login(email: "member@example.com", password: "password") { token user { name role } }
}{
me { name role organization { name memberCount } }
posts(first: 5) {
edges { cursor node { title status publishedAt author { name } } }
pageInfo { hasNextPage endCursor total }
}
search(term: "Acme") {
__typename
... on Post { title }
... on Organization { name }
}
}Where each feature lives
Every row is backed by at least one test under tests/Feature/GraphQL, so the corresponding guide pages can show real code rather than sketches.
| Feature | Example source | Guide |
|---|---|---|
Object types, per-field resolvers, #[Fillable] models | UserType, PostType | Types |
Field-level visibility — declarative canSee (ability + closure shapes) | UserType::email, OrganizationType::settings | Authentication & authorization |
| Input objects | PostInputType | Types |
| Native PHP enums | UserRole, PostStatus | Types |
Interfaces, unions, Relay Node | NodeType, SearchResultType | Types, Pagination |
Custom + database scalars (DateTime, JSON, Upload) | OrganizationType, UploadAvatarMutation | Types, The HTTP API |
Queries, arguments, validation rules, complexity() | SearchQuery, PostsQuery | Queries & mutations |
Mutations, authorize(), custom coded errors | LoginMutation with InvalidCredentialsException | Queries & mutations, Error handling |
FormRequest reuse — formRequest() sharing one ruleset with REST | UpdateProfileMutation, UpdateProfileRequest | Queries & mutations |
Guards (JWT), policies, policy() shortcut | UserQuery, UsersQuery, PostPolicy | Authentication & authorization |
batchRelation() and custom DataLoaders | MemberCountLoader | Relations & DataLoaders |
Relay cursor pagination and node(id:) re-fetching | PostsQuery, NodeType | Pagination |
| Subscriptions (Broadcast driver, channel authorization) | PostPublishedSubscription | Subscriptions |
| GraphQL over HTTP: GET, batching, APQ persisted queries, uploads, error codes | HttpProtocolTest | The HTTP API |
Multiple isolated schemas (default + admin) | Admin/StatsQuery, config/laragraph.php | Multiple schemas |
| Security limits and a custom validation rule | MaxRootFieldsRule | Security |
| Response cache + invalidation, Octane | FlushResponseCacheAfterMutations, OctaneTest | Performance & caching |
Events, response extensions (requestId, timing, queryComplexity), custom extensions | LogSlowGraphQLOperations, ApiVersionExtension | Observability |
Testing helpers (graphql() over HTTP with real tokens) | GraphQLTestCase | Testing |
Artisan commands (validate, cache, schema:export) | ToolingTest | Deployment |
| Localized error messages | LocalizationTest | Error handling |
Run its tests
The suite is part of the repository's CI:
cd example
php artisan test # 75+ feature tests over real HTTPBecause the app installs the package from .., these tests always exercise the working tree — when they pass, the code the guides show works with the version you're reading. If you fork the package, change a feature in src/, and break the example, this suite is what tells you the docs have gone stale.
Reading order
A good way to learn Laragraph end-to-end: Getting started → open UserType and follow its links in the Types guide → authentication (including canSee) → relations → pagination, checking each concept off in GraphiQL as you go.