Skip to content

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:

bash
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 serve

Then 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):

EmailRole
admin@example.comAdmin of "Acme Corporation"
member@example.comMember 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:

graphql
mutation {
  login(email: "member@example.com", password: "password") { token user { name role } }
}
graphql
{
  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.

FeatureExample sourceGuide
Object types, per-field resolvers, #[Fillable] modelsUserType, PostTypeTypes
Field-level visibility — declarative canSee (ability + closure shapes)UserType::email, OrganizationType::settingsAuthentication & authorization
Input objectsPostInputTypeTypes
Native PHP enumsUserRole, PostStatusTypes
Interfaces, unions, Relay NodeNodeType, SearchResultTypeTypes, Pagination
Custom + database scalars (DateTime, JSON, Upload)OrganizationType, UploadAvatarMutationTypes, The HTTP API
Queries, arguments, validation rules, complexity()SearchQuery, PostsQueryQueries & mutations
Mutations, authorize(), custom coded errorsLoginMutation with InvalidCredentialsExceptionQueries & mutations, Error handling
FormRequest reuse — formRequest() sharing one ruleset with RESTUpdateProfileMutation, UpdateProfileRequestQueries & mutations
Guards (JWT), policies, policy() shortcutUserQuery, UsersQuery, PostPolicyAuthentication & authorization
batchRelation() and custom DataLoadersMemberCountLoaderRelations & DataLoaders
Relay cursor pagination and node(id:) re-fetchingPostsQuery, NodeTypePagination
Subscriptions (Broadcast driver, channel authorization)PostPublishedSubscriptionSubscriptions
GraphQL over HTTP: GET, batching, APQ persisted queries, uploads, error codesHttpProtocolTestThe HTTP API
Multiple isolated schemas (default + admin)Admin/StatsQuery, config/laragraph.phpMultiple schemas
Security limits and a custom validation ruleMaxRootFieldsRuleSecurity
Response cache + invalidation, OctaneFlushResponseCacheAfterMutations, OctaneTestPerformance & caching
Events, response extensions (requestId, timing, queryComplexity), custom extensionsLogSlowGraphQLOperations, ApiVersionExtensionObservability
Testing helpers (graphql() over HTTP with real tokens)GraphQLTestCaseTesting
Artisan commands (validate, cache, schema:export)ToolingTestDeployment
Localized error messagesLocalizationTestError handling

Run its tests ​

The suite is part of the repository's CI:

bash
cd example
php artisan test                  # 75+ feature tests over real HTTP

Because 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.

Released under the MIT License.