pixelandtonic/graphql-php
PHP implementation of the GraphQL specification (based on graphql-js). Build schemas, execute queries, and add custom types, fields, and resolvers. Install via Composer and explore full docs and ready-to-run examples.
StandardServer (PSR-7 compliant).Route::middleware() can wrap GraphQL endpoints (e.g., /graphql). The package provides a GraphQLHTTP facade for quick setup.graphql-php/eloquent extension).resolve functions access Auth::user()).| Laravel Component | GraphQL-PHP Integration | Notes |
|---|---|---|
| Routing | Route::post('/graphql', [GraphQLController::class, 'handle']) |
Uses PSR-7 StandardServer. |
| Middleware | GraphQL::middleware() or Laravel’s middleware() |
Add auth, CORS, etc. |
| Service Providers | Register schema in boot() |
Define resolvers, types, and directives. |
| Eloquent | graphql-php/eloquent extension |
Auto-generates types from models. |
| Cache | GraphQL::cache() |
Cache query plans and parsed schemas. |
| Validation | Schema validation (SDL) | Catches errors at build time. |
| Testing | GraphQL::test() helper |
Write unit tests for resolvers. |
| Frontend | Apollo Client, Relay, or raw HTTP | Use Laravel Mix for client-side GraphQL. |
/graphql endpoint with a minimal schema (e.g., User type).barryvdh/laravel-ide-helper for autocompletion.zendframework/zend-diactoros (included via Laravel HTTP).graphql-php/eloquent, graphql-php/laravel (for tighter integration).type User {
id: ID!
name: String!
posts: [Post!]!
}
$schema->type('User', [
'fields' => [
'posts' => function($root) {
return $root->posts()->get();
},
],
]);
Route::post('/graphql', function () {
return GraphQL::execute(
request()->input('query'),
request()->input('variables')
);
})->middleware('auth:api');
@deprecated) for backward compatibility.webonyx/graphql-php for breaking changes (e.g., v14.x).GraphQL::validate())./graphql endpoint.| Failure Scenario | Mitigation | Detection |
|---|---|---|
| Malformed queries | Validate with GraphQL::validate() |
Log errors via GraphQL::errorHandler. |
| Resolver exceptions | Wrap in try-catch and return formatted errors. |
Monitor Laravel logs. |
| Schema misconfiguration | Use SDL validation and CI checks. | Test schema with GraphQL::buildSchema. |
| Database timeouts | Implement retries with exponential backoff. | Monitor query execution time. |
| **Denial-of |
How can I help you explore Laravel packages today?